\u521b\u5efa\u811a\u672c\u6587\u4ef6\u5e76\u6dfb\u52a0\u6267\u884c\u6743\u9650<\/p>\n
\r\n\u3000\u3000touch \/etc\/init.d\/nginx\r\n\r\n\u3000\u3000chmod +x \/etc\/init.d\/nginx\r\n<\/pre>\n\u7f16\u5199\u811a\u672c\u5185\u5bb9<\/p>\n
\r\n\u3000\u3000#!\/bin\/bash\r\n\r\n\u3000\u3000# chkconfig: - 85 15\r\n\r\n\u3000\u3000# description: Nginx server control script\r\n\r\n\u3000\u3000# processname: nginx\r\n\r\n\u3000\u3000# config file: \/usr\/local\/nginx\/conf\/nginx.conf\r\n\r\n\u3000\u3000# pid file: \/usr\/local\/nginx\/logs\/nginx.pid\r\n\r\n\u3000\u3000#\r\n\r\n\u3000\u3000# eastmoney public tools\r\n\r\n\u3000\u3000# version: v1.0.0\r\n\r\n\u3000\u3000# create by XuHoo, 2016-9-14\r\n\r\n\u3000\u3000#\r\n\r\n\u3000\u3000# source function library\r\n\r\n\u3000\u3000. \/etc\/rc.d\/init.d\/functions\r\n\r\n\u3000\u3000NGINX_NAME=\"nginx\"\r\n\r\n\u3000\u3000NGINX_PROG=\"\/usr\/local\/sbin\/nginx\"\r\n\r\n\u3000\u3000NGINX_PID_FILE=\"\/usr\/local\/nginx\/logs\/nginx.pid\"\r\n\r\n\u3000\u3000NGINX_CONF_FILE=\"\/usr\/local\/nginx\/conf\/nginx.conf\"\r\n\r\n\u3000\u3000NGINX_LOCK_FILE=\"\/var\/lock\/subsys\/nginx.lock\"\r\n\r\n\u3000\u3000# check current user\r\n\r\n\u3000\u3000[ \"$USER\" != \"root\" ] && exit 1\r\n\r\n\u3000\u3000start() {\r\n\r\n\u3000\u3000status\r\n\r\n\u3000\u3000if [[ $? -eq 0 ]]; then\r\n\r\n\u3000\u3000echo $\"Nginx (PID $(cat $NGINX_PID_FILE)) already started.\"\r\n\r\n\u3000\u3000return 1\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000echo -n $\"Starting $NGINX_NAME: \"\r\n\r\n\u3000\u3000daemon $NGINX_PROG -c $NGINX_CONF_FILE\r\n\r\n\u3000\u3000retval=$?\r\n\r\n\u3000\u3000echo\r\n\r\n\u3000\u3000[ $retval -eq 0 ] && touch $NGINX_LOCK_FILE\r\n\r\n\u3000\u3000return $retval\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000stop() {\r\n\r\n\u3000\u3000status\r\n\r\n\u3000\u3000if [[ $? -eq 1 ]]; then\r\n\r\n\u3000\u3000echo \"Nginx server already stopped.\"\r\n\r\n\u3000\u3000return 1\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000echo -n $\"Stoping $NGINX_NAME: \"\r\n\r\n\u3000\u3000killproc $NGINX_PROG\r\n\r\n\u3000\u3000retval=$?\r\n\r\n\u3000\u3000echo\r\n\r\n\u3000\u3000[ $retval -eq 0 ] && rm -f $NGINX_LOCK_FILE\r\n\r\n\u3000\u3000return $retval\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000restart() {\r\n\r\n\u3000\u3000stop\r\n\r\n\u3000\u3000sleep 1\r\n\r\n\u3000\u3000start\r\n\r\n\u3000\u3000retval=$?\r\n\r\n\u3000\u3000return $retval\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000reload() {\r\n\r\n\u3000\u3000echo -n $\"Reloading $NGINX_NAME: \"\r\n\r\n\u3000\u3000killproc $NGINX_PROG -HUP\r\n\r\n\u3000\u3000retval=$?\r\n\r\n\u3000\u3000echo\r\n\r\n\u3000\u3000return $retval\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000status() {\r\n\r\n\u3000\u3000netstat -anpt | grep \"\/nginx\" | awk '{print $6}' &> \/dev\/null\r\n\r\n\u3000\u3000if [[ $? -eq 0 ]]; then\r\n\r\n\u3000\u3000if [[ -f $NGINX_LOCK_FILE ]]; then\r\n\r\n\u3000\u3000return 0\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000return 1\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000return 1\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000_status() {\r\n\r\n\u3000\u3000status\r\n\r\n\u3000\u3000if [[ $? -eq 0 ]]; then\r\n\r\n\u3000\u3000state=`netstat -anpt | grep \"\/nginx\" | awk '{ print $6 }'`\r\n\r\n\u3000\u3000echo $\"Nginx server status is: $state\"\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000echo \"Nginx server is not running\"\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000test() {\r\n\r\n\u3000\u3000$NGINX_PROG -t -c $NGINX_CONF_FILE\r\n\r\n\u3000\u3000retval=$?\r\n\r\n\u3000\u3000return $retval\r\n\r\n\u3000\u3000}\r\n\r\n\u3000\u3000case \"$1\" in\r\n\r\n\u3000\u3000start)\r\n\r\n\u3000\u3000start\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000stop)\r\n\r\n\u3000\u3000stop\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000reload)\r\n\r\n\u3000\u3000reload\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000restart)\r\n\r\n\u3000\u3000restart\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000status)\r\n\r\n\u3000\u3000_status\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000test)\r\n\r\n\u3000\u3000test\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000*)\r\n\r\n\u3000\u3000echo \"Usage: { start | stop | reload | restart | status | test }\"\r\n\r\n\u3000\u3000exit 1\r\n\r\n\u3000\u3000esac\r\n<\/pre>\n\u5c06\u811a\u672c\u6dfb\u52a0\u5230\u7cfb\u7edf\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8<\/p>\n
\r\n\u3000\u3000chkconfig --add nginx\r\n\r\n\u3000\u3000chkconfig --level 3 nginx on\r\n<\/pre>\n\u811a\u672c\u4e8c<\/strong><\/span><\/div>\n\r\n\u3000\u3000[root@localhost ~]# cd \/usr\/local\/nginx\/conf\/\r\n\r\n\u3000\u3000[root@localhost conf]# ls\r\n\r\n\u3000\u3000fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf\r\n\r\n\u3000\u3000fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default\r\n<\/pre>\n\u5907\u4efd\u4e3b\u914d\u7f6e\u6587\u4ef6<\/p>\n
\r\n\u3000\u3000[root@localhost conf]# cp nginx.conf nginx.conf.origin\r\n\r\n\u3000\u3000[root@localhost conf]# vim nginx.conf\r\n\r\n\u3000\u3000\u53bb\u9664#pid logs\/nginx.pid;\u524d\u9762#\u53f7\r\n<\/pre>\n\r\n\u3000\u3000[root@localhost conf]# netstat -anpt | grep 80\r\n\r\n\u3000\u3000tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19108\/nginx\r\n\r\n\u3000\u3000[root@localhost conf]# kill -3 19108\r\n\r\n\u3000\u3000[root@localhost conf]# netstat -anpt | grep 80\r\n\r\n\u3000\u3000[root@localhost conf]# nginx\r\n\r\n\u3000\u3000[root@localhost conf]# netstat -anpt | grep 80\r\n\r\n\u3000\u3000tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19864\/nginx\r\n\r\n\u3000\u3000[root@localhost conf]# cd ..\/logs\/\r\n\r\n\u3000\u3000[root@localhost logs]# ls\r\n\r\n\u3000\u3000access.log error.log nginx.pid\r\n\r\n\u3000\u3000[root@localhost logs]# cat nginx.pid\r\n\r\n\u3000\u300019864\r\n<\/pre>\n\u7f16\u8f91\u5199\u670d\u52a1\u811a\u672c<\/p>\n
\r\n\u3000\u3000[root@localhost ~]# vim \/etc\/init.d\/nginx\r\n\r\n\u3000\u3000\u53ef\u4ee5\u4f7f\u7528\u7684\u9009\u9879\u6709\uff1a\r\n\r\n\u3000\u3000start\u3000\u3000\u3000 \u542f\u52a8\r\n\r\n\u3000\u3000stop\u3000\u3000\u3000 \u505c\u6b62\r\n\r\n\u3000\u3000reload\u3000\u3000\u3000\u91cd\u8f7d\r\n\r\n\u3000\u3000restart \u3000\u3000 \u91cd\u542f\r\n\r\n\u3000\u3000status\u3000\u3000 \u72b6\u6001\r\n\r\n\u3000\u3000test\u3000\u3000\u3000\u3000\u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\r\n<\/pre>\n\r\n\u3000\u3000#!\/bin\/bash\r\n\r\n\u3000\u3000#chkconfig: 2345 99 20\r\n\r\n\u3000\u3000#description:Nginx Server Control Scripts shell\r\n\r\n\u3000\u3000PROG=\"\/usr\/local\/nginx\/sbin\/nginx\"\r\n\r\n\u3000\u3000PIDF=\"\/usr\/local\/nginx\/logs\/nginx.pid\"\r\n\r\n\u3000\u3000case \"$1\" in\r\n\r\n\u3000\u3000start)\r\n\r\n\u3000\u3000if [ -f $PIDF ];\r\n\r\n\u3000\u3000then\r\n\r\n\u3000\u3000echo \"Nginx\u6b63\u5728\u8fd0\u884c\u2026\"\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000$PROG\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000stop)\r\n\r\n\u3000\u3000if [ -f $PIDF ];\r\n\r\n\u3000\u3000then\r\n\r\n\u3000\u3000kill -3 $(cat $PIDF)\r\n\r\n\u3000\u3000rm -f $PIDF\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000echo \"Nginx\u6b63\u5728\u505c\u6b62\u2026\"\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000restart)\r\n\r\n\u3000\u3000$0 stop\r\n\r\n\u3000\u3000$0 start\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000reload)\r\n\r\n\u3000\u3000if [ -f $PIDF ];\r\n\r\n\u3000\u3000then\r\n\r\n\u3000\u3000kill -1 $(cat $PIDF)\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000echo \"Nginx\u6b63\u5728\u505c\u6b62\u2026\u91cd\u65b0\u52a0\u8f7d\"\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000status)\r\n\r\n\u3000\u3000if [ -f $PIDF ];\r\n\r\n\u3000\u3000then\r\n\r\n\u3000\u3000echo \"Nginx\u6b63\u5728\u8fd0\u884c\"\r\n\r\n\u3000\u3000else\r\n\r\n\u3000\u3000echo \"Nginx\u505c\u6b62\"\r\n\r\n\u3000\u3000fi\r\n\r\n\u3000\u3000;;\r\n\r\n\u3000\u3000*)\r\n\r\n\u3000\u3000echo \"Usage: $0 (start|stop|restart|reload|status)\"\r\n\r\n\u3000\u3000exit 1\r\n\r\n\u3000\u3000esac\r\n\r\n\u3000\u3000exit 0\r\n<\/pre>\n\u811a\u672c\u6587\u4ef6\u5e76\u6dfb\u52a0\u6267\u884c\u6743\u9650<\/p>\n
\r\n\u3000\u3000[root@localhost ~]# chmod +x \/etc\/init.d\/nginx\r\n\r\n \u5c06\u811a\u672c\u6dfb\u52a0\u5230\u7cfb\u7edf\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\r\n\r\n\u3000\u3000[root@localhost ~]# chkconfig --add nginx\r\n\r\n\u3000\u3000\u6dfb\u52a0\u4e3a\u670d\u52a1\u542f\u52a8\u9879\r\n\r\n\u3000\u3000[root@localhost ~]# chkconfig --list nginx\r\n\r\n\u3000\u3000nginx 0:\u5173\u95ed 1:\u5173\u95ed 2:\u542f\u7528 3:\u542f\u7528 4:\u542f\u7528 5:\u542f\u7528 6:\u5173\u95ed\r\n\r\n\u3000\u3000[root@localhost ~]# chkconfig --level 3 nginx on\r\n\r\n\u3000\u3000\u6d4b\u8bd5\u811a\u672c\u662f\u5426\u80fd\u591f\u6267\u884c\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx start\r\n\r\n\u3000\u3000Nginx\u6b63\u5728\u8fd0\u884c\u2026\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx restart\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx stop\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx stop\r\n\r\n\u3000\u3000Nginx\u6b63\u5728\u505c\u6b62\u2026\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx start\r\n\r\n\u3000\u3000[root@localhost ~]# service nginx status\r\n\r\n\u3000\u3000Nginx\u6b63\u5728\u8fd0\u884c\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u9009\u9879\u6709\uff1a \u3000\u3000start\u3000\u3000\u3000 \u542f\u52a8 \u3000\u3000stop\u3000\u3000\u3000 \u505c\u6b62 \u3000\u3000reload\u3000\u3000\u3000\u91cd\u8f7d \u3000\u3000restart […]<\/p>\n","protected":false},"author":668,"featured_media":15116,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-150804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=150804"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150804\/revisions"}],"predecessor-version":[{"id":150926,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/150804\/revisions\/150926"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/15116"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=150804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=150804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=150804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}