nginx设置开启自启动

nginx安装完成后nginx1.24.0安装,为了保证主机出现异常重启后依然保证能及时提供服务,需要配置开启自启任务。

1、编写nginx.service
vi 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
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID 
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install] 
WantedBy=multi-user.target

usr/local/nginx/目录为nginx的安装目录,根据自己安装nginx目录做调整

将nginx.service移动到/usr/lib/systemd/system/目录下
cp ./nginx.service /usr/lib/systemd/system/

重启配置服务
systemctl daemon-reload

查看nginx服务状态
systemctl status nginx

可见此时nginx服务状态是关闭的

启动nginx.service服务并再次查看状态
systemctl start nginx
systemctl status nginx

配置nginx开机自启
systemctl enable nginx

完成!

你可能感兴趣的:(nginx,nginx,linux,运维,1024程序员节)