CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了centos设置nginx开机启动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

一、看看/etc/inid.d下面有没有nginx文件,没有就创建 vi /etc/inid.d/nginx 该文件内容如下: #!/bin/bash # nginx Startup script for the Nginx http Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a hig

一、看看/etc/inid.d下面有没有Nginx文件,没有就创建 vi /etc/inid.d/Nginx文件内容如下: #!/bin/bash # Nginx Startup script for the Nginx http Server # it is v.0.0.2 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.conf Nginxd=/usr/local/Nginx/sbin/Nginx Nginx_config=/usr/local/Nginx/conf/Nginx.conf Nginx_pid=/var/run/Nginx.pid RETVAL=0 prog="Nginx" # source function library. . /etc/rc.d/init.d/functions # source networking configuration. . /etc/sysconfig/network # check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $Nginxd ] || exit 0 # Start Nginx daemons functions. start() { if [ -e $Nginx_pid ];then echo "Nginx already running...." exit 1 fi 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 /var/run/Nginx.pid } # reload Nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${Nginx_piD}` killproc $Nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|Help}" exit 1 esac exit $RETVAL 注意红色加粗部分,需要将路径改为自己机器的相应路径。 接着,设置文件的访问权限: chmod a+x /etc/init.d/Nginx (a+x参数表示 ==> all user can execute 所有用户可执行) 二、建立服务文件 vi /lib/systemd/system/Nginx.service 内容如下: [Unit] Description=Nginx After=network.target [service] Type=forking ExecStart=/etc/init.d/Nginx start ExecReload=/etc/init.d/Nginx restart ExecStop=/etc/init.d/Nginx stop PrivateTmp=true [Install] WantedBy=multi-user.target 三、 设置开机自启动 执行命令: systemctl enable Nginx.service 参文章http://blog.163.com/qsc0624@126/blog/static/140324073201312734548701/ https://yq.aliyun.com/articles/66323

大佬总结

以上是大佬教程为你收集整理的centos设置nginx开机启动全部内容,希望文章能够帮你解决centos设置nginx开机启动所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。