The nginx startup script we see on the web is usually /etc/rc.d/init.d/nginx This script, whose contents are:
#!/bin/bash# nginx startup script for the nginx http server# it is v.1.3.0 version.# chkconfig: - 85 15# description: nginx is a high-performance web and proxy server.# It has a lot of features, But it ' s not for everyone.# processname: nginx# pidfile: /var/run/ nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/ Usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidretval=0prog= "Nginx" # Source function library. /etc/rc.d/init.d/functions# source networking configuration. /etc/sysconfig/network# check that networking is up. [ ${networking} = "No" &nbsP;] && exit 0[ -x $nginxd ] | | exit 0# start nginx daemons functions.start () {if [ -e $ nginx_pid ];then echo "Nginx already running ..." exit 1fi echo -n $ "starting $prog: " daemon $ nginxd -c ${nginx_config} retval=$? echo [ $ Retval = 0 ] && touch /var/lock/subsys/nginx return $RETVAL}# stop nginx daemons functions.stop () { echo -n $ "stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx / Usr/local/nginx/logs/nginx.pid}reload () { echo -n $ "Reloading $prog : " #kill -HUP ' cat ${nginx_pid} ' killproc $NGINXD -HUP RETVAL=$? echo}# See how we were called.case "$" instart) start ;; Stop) stop ;; Reload) reload ;; Restart) stop start ;; Status) status $prog RETVAL=$? ;; *) echo $ "usage: $prog {start|stop|restart| RELOAD|STATUS|HELP} " exit 1esacexit $RETVAL
For this script, I was previously on some Linux servers (CentOS? ), but when installing Nginx on the Redhat, I suddenly found that the script did not start the nginx.
Finally, the solution is solved by accessing the data, and the solutions are as follows:
(1) Backup script:
[Email protected] init.d]# mv Nginx Nginx.bak
(2) New nginx.service:
[Email protected] init.d]# Vim/usr/lib/systemd/system/nginx.service
The contents are as follows:
[unit]description=nginx - high performance web Serverdocumentation=http://nginx.org/en/docs/after=network.target remote-fs.target nss-lookup.target [Service] Type=forkingpidfile=/usr/local/nginx/logs/nginx.pidexecstartpre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confexecstart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf /nginx.confexecreload=/bin/kill -s hup $MAINPIDExecStop =/bin/kill -s quit $ Mainpidprivatetmp=true[install]wantedby=multi-user.target
(3) Give this script the right:
[Email protected] init.d]# chmod a+x/usr/lib/systemd/system/nginx.service
(4) Close Nginx and other:
[Email protected] init.d]# fuser-k 80/tcp[[email protected] init.d]# systemctl daemon-reload[[email protected] init.d]# Service Nginx Stop
(5) Start Nginx:
[[Email protected] system]# service Nginx start
(6) Check the status of Nginx:
[[Email protected] system]# service Nginx status
The final effect is as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/90/wKiom1eohcaDZtCxAAChkV4QaZ4248.png "title=" 20160611175744465.png "alt=" Wkiom1eohcadztcxaachkv4qaz4248.png "/>
This article is from "Zifangsky's personal blog" blog, make sure to keep this source http://983836259.blog.51cto.com/7311475/1835813
Troubleshoot an Nginx startup script that is incompatible on Redhat