nginx添加到service启动

硅谷探秘者 Md nginx 1122 0 0

nginx安装参考:linux centos7环境nginx安装配置

/etc/init.d/文件夹下创建nginx文件,并写入如下内容:

vi /etc/init.d/nginx

#!/bin/bash  
# nginx Startup script for the Nginx HTTP Server  
#  
# 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 

########### need to modify  the path ###################
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: " 
 $nginxd -s reload  
    #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`" 
    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

注意:以下参数要修改成你nginx安装时配置的值

nginxd=/usr/local/nginx/sbin/nginx  
nginx_config=/usr/local/nginx/conf/nginx.conf  
nginx_pid=/var/run/nginx.pid

执行命令:

[root@localhost /]# cd /etc/rc.d/init.d
[root@localhost init.d]# chmod +x nginx
[root@localhost init.d]# /sbin/chkconfig --level 345 nginx on

此时在任何位置都可以运行: service nginx start

可选 start | stop | restart | reload | status | help


评论区
请写下您的评论...
暂无评论...
猜你喜欢
框架 6319 javaspringboot或移除定时器(定时任务)工具类importjava.lang.reflect.Field;importjava.lang.reflect.Method
java基础,springboot 1341 SpringBoot作为Service。 一、Maven打包在pom.xml配置文件中 build plugins plugin groupIdorg.springframework.boot
工具 2243 1.在redis的安装目录下(或随便某个目录)创建一个redis.bat文件,并内容如下:::redis的命令@echooff::输出提示语echoredisstart......::设置
其他 2451 linux环境下开机自tomcat1.修改脚本文件rc.local这个脚本是使用者自定的开机程序,可以在里面想在系统之后执行的脚本或者脚本执行命令vim/etc/rc.d
java基础 3548 java并发编程之service层处理并发事务锁可能会无效最近注意一个问题--在service层处理要多次操作数据库事务时往往要@Transactional事务注解,这个时候就要注意了,如果是在
nginx 1077 :20htmldrwxr-xr-x.2rootroot61月712:20logsdrwxr-xr-x.2rootroot191月712:20sbin四、nginx  在安装目录下执行命令:[root
linux系统 1362 nginx配置负载均衡以及负载均衡的策略的选取(linux)一、nginx配置负载均衡安装nginx,修改conf/nginx.conf配置文件在http块下#配置态服务器列表
spring/springmvc 4353 springmvc项目时执行controller在springmvc的配置文件中入controller的bean,注意bean载的顺序beanclass
归档
2018-11  12 2018-12  33 2019-01  28 2019-02  28 2019-03  32 2019-04  27 2019-05  33 2019-06  6 2019-07  12 2019-08  12 2019-09  21 2019-10  8 2019-11  15 2019-12  25 2020-01  9 2020-02  5 2020-03  16 2020-04  4 2020-06  1 2020-07  7 2020-08  13 2020-09  9 2020-10  5 2020-12  3 2021-01  1 2021-02  5 2021-03  7 2021-04  4 2021-05  4 2021-06  1 2021-07  7 2021-08  2 2021-09  8 2021-10  9 2021-11  16 2021-12  14 2022-01  7 2022-05  1 2022-08  3 2022-09  2 2022-10  2 2022-12  5 2023-01  3 2023-02  1 2023-03  4 2023-04  2 2023-06  3 2023-07  4 2023-08  1 2023-10  1 2024-02  1 2024-03  1 2024-04  1
标签
算法基础 linux 前端 c++ 数据结构 框架 数据库 计算机基础 储备知识 java基础 ASM 其他 深入理解java虚拟机 nginx git 消息中间件 搜索 maven redis docker dubbo vue 导入导出 软件使用 idea插件 协议 无聊的知识 jenkins springboot mqtt协议 keepalived minio mysql ensp 网络基础 xxl-job rabbitmq haproxy srs 音视频 webrtc javascript
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。