centos-rhel服务器相关 / nginx / 未分类 · 2015年7月30日

centos7添加nginx 服务并自启动

作为服务,开机后启动
增加以下内容
[[email protected] ~]# vi /usr/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= /usr/local/nginx/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -t
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

[[email protected] ~]# systemctl enable nginx.service
[[email protected] ~]# systemctl list-unit-files|grep enabled|grep nginx
启动服务
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl start nginx.service
[[email protected] ~]# systemctl status nginx.service -l
[[email protected] ~]# ps -ef|grep nginx
#这样也可以 但是不太标准
systemctl start nginx