当前位置: 首页 > Linux

linux环境开机启动nginx

时间:2023-04-07 01:35:07 Linux

一、编写脚本vi/etc/init.d/nginx修改/etc/init.d/nginx代码如下:#!/bin/bash#nginxHTTPServer的启动脚本#是v.0.0.2版本。#chkconfig:-8515#描述:Nginx是一个高性能的web和代理服务器。#它有很多特性,但并不适合所有人。#processname:nginx#pidfile:/var/run/nginx.pid#配置:/usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/var/run/nginx.pidRETVAL=0prog="nginx"#源函数库../etc/rc.d/init.d/functions#源网络配置../etc/sysconfig/network#检查网络是否正常。[${NETWORKING}="no"]&&退出0[-x$nginxd]||exit0#Startnginxdaemonsfunctions.start(){if[-e$nginx_pid];thenecho"nginxalreadyrunning..."exit1fiecho-n$"Starting$prog:"daemon$nginxd-c${nginx_config}RETVAL=$?echo[$RETVAL=0]&&touch/var/lock/subsys/nginxreturn$RETVAL}#Stopnginxdaemonsfunctions.stop(){echo-n$"Stopping$prog:"killproc$nginxdRETVAL=$?echo[$RETVAL=0]&&rm-f/var/lock/subsys/nginx/var/run/nginx.pid}#reloadnginxservicefunctions.reload(){echo-n$"Reloading$prog:"#kill-HUP`cat${nginx_pid}`killproc$nginxd-HUPRETVAL=$?echo}#看看我们是怎么调用的。case"$1"instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status$progRETVAL=$?;;*)echo$"Usage:$prog{start|stop|restart|reload|status|help}"exit1esacexit$RETVAL:wq保存退出2.设置文件权限chmoda+x/etc/init.d/nginx3.修改/etc/rc.localvi/etc/rc.local添加一行代码如下:/etc/init.d/nginxstart:wq保存退出4.重启