nginx设置自动启动
首先创建nginx相关服务脚本
进入系统服务脚本目录
cd /usr/lib/systemd/system
创建ngxin服务相关脚本
touch nginx.service
内容如下
(注意我的目录是tools/nginx,根据需要进行更改)
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/tools/nginx/logs/nginx.pid
ExecStartPre=/tools/nginx/sbin/nginx -t -c /tools/nginx/conf/nginx.conf
ExecStart=/tools/nginx/sbin/nginx -c /tools/nginx/conf/nginx.conf
ExecReload=/tools/nginx/sbin/nginx -s reload
ExecStop=/tools/nginx/sbin/nginx -s stop
ExecQuit=/tools/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
启动服务
systemctl start nginx.service
开机启动
systemctl enable nginx.service
查看系统服务状态
systemctl status nginx.service