如果是yum直接安装的
直接用命令systemcel enable nginx.service
设置开机自启即可
如果是通过源码安装的
vi /lib/systemd/system/nginx.service
内容:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable nginx.service
设置开机启动