将nginx添加为系统服务
则可以使用以下命令来管理nginx
systemctl start nginx systemctl status nginx systemctl stop nginx systemctl restart nginx
直接编辑文件
vim /lib/systemd/system/nginx.service
将以下内容复制粘贴保存,路径按照实际路径填写。
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStartPre=/app/nginx/sbin/nginx -t -c /app/nginx/conf/nginx.conf ExecStart=/app/nginx/sbin/nginx -c /app/nginx/conf/nginx.conf ExecReload=/app/nginx/sbin/nginx -s reload ExecStop=/app/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
执行重启systemctl,实现nginx开机自启
systemctl daemon-reload systemctl enable nginx