使用systemctl来管理手动编译安装的Nginx
FastDFS(https://github.com/happyfish100/fastdfs/wiki)推荐的nginx启动方式是直接执行/usr/local/nginx/sbin/nginx
如果配成用systemctl管理的话,更符合常规使用习惯,而且可以设为开机启动,具体如下:
- /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- Reload and enable
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
注:如果是ubuntu则需编辑/etc/systemd/system/nginx.service
内容可简化为:
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/www/server/nginx/logs/nginx.pid
ExecStartPre=nginx -t
ExecStart=nginx
ExecReload=nginx -s reload
ExecStop=nginx -s stop
ExecQuit=nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target