安装
$ cd /usr/local/
$ sudo wget http://nginx.org/download/nginx-1.8.0.tar.gz
$ sudo tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0
$ sudo ./configure --prefix=/usr/local/nginx
$ sudo make
$ sudo make install
添加nginx系统服务
cd /lib/systemd/system
#编写脚本,建议直接复制
vim nginx.service
#!/bin.bash
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target'
##磁盘上的ngin服务更改,运行'systemctl daemon-reload'重新加载单元。
systemctl daemon-reload
chmod 755 /usr/lib/systemd/system/nginx.service
##启动服务
systemctl start nginx
systemctl enable nginx #开机自启
systemctl status nginx