Can
Be Better

centos 7.2 nginx 开机启动

摘要

运行环境

Fedora, OpenSUSE, Arch Linux, Ubuntu. Tested on Fedora 16 and 17, Ubuntu 18.04 ,Centos7

 文件位置

/lib/systemd/system/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
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

系统指令

启动nginx服务
systemctl start nginx.service
设置开机自启动
systemctl enable nginx.service
停止开机自启动
systemctl disable nginx.service
查看服务当前状态
systemctl status nginx.service
重新启动服务
systemctl restart nginx.service
查看所有已启动的服务
systemctl list-units –type=service

不开启评论,如有问题疑问请发邮件。i@ltq.im最长的路 » centos 7.2 nginx 开机启动