1、解压并安装
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install
2、添加nginx服务
vim /etc/systemd/system/nginx.service
添加以下内容插入
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3、nginx服务命令
# 设置开机自启
systemctl enable nginx
# 查看nginx状态
systemctl status nginx
# 启动nginx服务
systemctl start nginx
# 停止nginx服务
pkill nginx