nginx-安装&启动&停止&平滑重启

    科技2022-07-21  104

    一·下载上传安装包:

    http://nginx.org/en/download.html

    在上面网址找到自己需要的版本进行下载,让后上传到你的服务器上,我这里是nginx-1.13.9

    二·安装nginx

    2.1 可能出现的报错

    你的服务器上要有gcc,不然就会报下面的错,没有就yum -y install gcc 安装一下

    ./configure: error: C compiler cc is not found

    还要有pcre不然会有如下报错,yum -y install pcre-devel安装一下就好

    ./configure: error: the HTTP rewrite module requires the PCRE library.

    还有nginx默认是会安装HTTP_GZIP模块的,所以也需要gzip,没有的话会有如下报错,yum install -y zlib-devel安装一下就好

    ./configure: error: the HTTP gzip module requires the zlib library.

     

    2.2 安装过程

    【解压安装文件】

    tar zxvf nginx-1.13.9.tar.gz

    【进入安装文件目录】

    cd nginx-1.13.9

    【生成Makefile文件,为编译做准备】

    ./configure  --prefix=/usr/local/nginx (指定安装目录,其他的一些文件路径以及安装的模块都默认,可以根据需要安装一些模块或者进行一些配置) 编译完之后  输入内容的最后会有下面的内容,可以看到各个文件路径

      nginx path prefix: "/usr/local/nginx"【安装目录】   nginx binary file: "/usr/local/nginx/sbin/nginx"   nginx modules path: "/usr/local/nginx/modules"   nginx configuration prefix: "/usr/local/nginx/conf"【配置文件目录】   nginx configuration file: "/usr/local/nginx/conf/nginx.conf"【配置文件路径】   nginx pid file: "/usr/local/nginx/logs/nginx.pid"【进程文件路径】   nginx error log file: "/usr/local/nginx/logs/error.log"【错误日志路径】   nginx http access log file: "/usr/local/nginx/logs/access.log"【访问日志路径】   nginx http client request body temporary files: "client_body_temp"   nginx http proxy temporary files: "proxy_temp"   nginx http fastcgi temporary files: "fastcgi_temp"   nginx http uwsgi temporary files: "uwsgi_temp"   nginx http scgi temporary files: "scgi_temp"

    【编译】

    make

    【安装】

    make install

    然后就安装完啦

    三·启动

    /usr/local/nginx/sbin/nginx   (-c 可以指定加载的配置文件)

    四·停止

    kill掉进程就好:

    【1】从容的停止nginx

     kill -QUIT 6563(nginx的进程id)

    【2】快速停止

    kill -TERM 6563(nginx的进程id)

    或者

    kill -INT 6563(nginx的进程id)

    【3】强制停止所有nginx进程

    pkill -9 nginx

    五·平缓重启

    kill -HUP 6445(nginx的进程id)

    如下我修改了nginx配置文件,将worker进程数量从1调整成2,kill -HUP 6445之后,worker进程变成了两个

       nginx收到HUP信号之后,会尝试先解析配置文件(没有指定配置文件就使用默认的)。

       如果成功就使用新的配置文件。之后,nginx运行新的工作进程并从容关闭旧的工作进程,通知工作进程关闭监听套接字,单是继续为当前连接的客户提供服务。所有客户端的服务完成后,旧的工作进程被关闭。

       如果新的配置文件应用失败,nginx将继续使用旧的配置进行工作

    Processed: 0.009, SQL: 8