linux nginx 基本用法

Posted 殁舞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux nginx 基本用法相关的知识,希望对你有一定的参考价值。

nginx -s reload -p <nginx环境目录> -c <指定的配置文件>

其中-p -c 为可选,不写为默认路径和配置

在执行命令之前可通过

nginx -t -p<> -c<>

检查自定义的配置文件是否正确

另外nginx停止命令为

ps -ef | grep nginx

kill -QUIT 30439<pid>

30439为图中的例子,为nginx master process的pid

再次启动命令

nginx -p<> -c<>

其中有个坑为reload命令仅支持改动配置文件,不支持更改文件,比如上图中目前运行的配置文件为nginx.conf,然后我修改这个文件再重启没问题

nginx -s reload -c conf/nginx.conf

但是如果我想换成conf/nginx.other.conf

nginx -s reload -c conf/nginx.other.conf

这是不生效的,他还是重新读取原来文件的配置

所以有多个配置文件需要切换的话,我的办法是重命名配置文件,将需要的配置文件名修改为nginx.conf

mv nginx.other.conf nginx.conf

实际中是为了蓝绿切换

切换脚本如下

case $1 in
    blue)
        if [ -f "nginx.blue.conf.bak" ]
        then
           mv nginx.conf nginx.green.conf.bak
           mv nginx.blue.conf.bak nginx.conf
           nginx -s reload -p /weblogic/nginx -c conf/nginx.conf
           echo \'切换到蓝\'
        else
           echo \'配置不存在\'
        fi
        ;; 
    green)
        if [ -f "nginx.green.conf.bak" ]
        then
           mv nginx.conf nginx.blue.conf.bak
           mv nginx.green.conf.bak nginx.conf
           nginx -s reload -p /weblogic/nginx -c conf/nginx.conf
           echo \'切换到绿组\'
        else
           echo \'配置不存在\'
        fi
        ;;
esac

切换命令为

sh cbd.sh blue/green

 

以上是关于linux nginx 基本用法的主要内容,如果未能解决你的问题,请参考以下文章

python调试:pdb基本用法(转)

将 nginx rtmp 片段发送到 WebRTC

Nginx:Nginx基本概念以及用法

nginx基本用法和HTTPS配置

Python中的基本函数及其常用用法简析

c_cpp 加载源图像固定用法(代码片段,不全)