本文介绍了在linux系统中,设置nginx开机自启动的配置步骤,设置开机自启动的方式使用的是systemctl,详细介绍如下:
# /usr/lib/systemd/system/下新建nginx.service文件
cd /usr/lib/systemd/system
touch nginx.service
# 然后在nginx.service中写入如下内容,
# 其中user和group为开启nginx的用户和对应用户组
[Unit]
Description=Nginx
After=nginx.service
[Service]
User=prouser
Group=rd
Type=forking
ExecStart=/opt/app/nginx/sbin/nginx -c /opt/app/nginx/conf/nginx.conf
ExecStop=/opt/app/nginx/sbin/nginx -s quit
ExecReload=/opt/app/nginx/sbin/nginx -s reload
Restart=on-failure
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 写入内容结束
systemctl daemon-reload # 重载配置
systemctl enable nginx # 设置开机自启动
systemctl disable nginx # 取消开机自启动
systemctl start nginx # 启动
systemctl stop nginx # 停止
systemctl relaod nginx # 重启