nginx的安装目录 : /usr/local/nginx
一、没有设置开机自启动前,需要执行/usr/local/nginx/sbin/nginx 启动
二、接下来,我们设置开机自启动,就不用手动启动nginx了
1、cd /usr/lib/systemd/system/
2、vi nginx.service
[unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.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.service文件,然后刷新systemd服务 systemctl daemon-reload
4、查看所有已启动的服务 systemctl list-units --type=service
5、启动、停止、重启服务
systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service
systemctl status nginx.service
6、开启/关闭开机自启动
systemctl enable nginx
systemctl disable nginx