作为服务,开机后启动
增加以下内容
[root@centos ~]# 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
[root@centos ~]# systemctl enable nginx.service
[root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx
启动服务
[root@centos ~]# systemctl daemon-reload
[root@centos ~]# systemctl start nginx.service
[root@centos ~]# systemctl status nginx.service -l
[root@centos ~]# ps -ef|grep nginx
#这样也可以 但是不太标准
systemctl start nginx