首页 > 系统相关 >nginx平滑升级

nginx平滑升级

时间:2022-10-12 23:12:09浏览次数:78  
标签:log -- 平滑 module 升级 nginx 1.22 localhost

nginx平滑升级

目录

一. 平滑升级

1、获取之前的编译参数

[root@localhost ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-debug --with-http_ssl_module --with-http_realip_module --with-htt
p_image_filter_module --with-http_gunzip_module --with-http_gzip_static_m
odule --with-http_stub_status_module --http-log-path=/var/log/nginx/acces
s.log --error-log-path=/var/log/nginx/error.log

2、下载新模块
https://github.com/openresty/echo-nginx-module
下载到本地,然后上传到nginx服务器

3、重新编译软件,加上–addmodule=新模块的解压路径

[root@localhost ~]# ls
anaconda-ks.cfg echo-nginx-module-master.zip nginx-1.22.0.tar.gz
[root@localhost ~]# yum -y install unzip
[root@localhost ~]# unzip echo-nginx-module-master.zip
[root@localhost ~]# tar -zxf nginx-1.22.0.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg echo-nginx-module-master.zip nginx-1.22.0.tar.
gz
echo-nginx-module-master nginx-1.22.0
[root@localhost ~]# cd nginx-1.22.0
[root@localhost nginx-1.22.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--add-module=../echo-nginx-module-master

查看objs目录下没有nginx程序

[root@localhost nginx-1.22.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@localhost nginx-1.22.0]# make
[root@localhost nginx-1.22.0]# ls objs
addon Makefile nginx.8 ngx_auto_headers.h ngx_module
s.o
autoconf.err nginx ngx_auto_config.h ngx_modules.c src

4、停止服务并备份原程序
升级前

[root@localhost ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-debug --with-http_ssl_module --with-http_realip_module --with-htt
p_image_filter_module --with-http_gunzip_module --with-http_gzip_static_m
odule --with-http_stub_status_module --http-log-path=/var/log/nginx/acces
s.log --error-log-path=/var/log/nginx/error.log

升级后

[root@localhost nginx-1.22.0]# objs/nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-debug --with-http_ssl_module --with-http_realip_module --with-htt
p_image_filter_module --with-http_gunzip_module --with-http_gzip_static_m
odule --with-http_stub_status_module --http-log-path=/var/log/nginx/acces
s.log --error-log-path=/var/log/nginx/error.log --add-module=../echo-ngin
x-module-master

5、把源程序用新程序覆盖

[root@localhost nginx-1.22.0]# cp /usr/local/nginx/sbin/nginx /opt/
[root@localhost nginx-1.22.0]# cp objs/nginx /usr/local/nginx/sbin/
cp: overwrite '/usr/local/nginx/sbin/nginx'? y
[root@localhost nginx-1.22.0]# /usr/local/nginx/sbin/nginx
[root@localhost nginx-1.22.0]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Pr
ocess
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost nginx-1.22.0]# nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-15) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
--with-debug --with-http_ssl_module --with-http_realip_module --with-htt
p_image_filter_module --with-http_gunzip_module --with-http_gzip_static_m
odule --with-http_stub_status_module --http-log-path=/var/log/nginx/acces
s.log --error-log-path=/var/log/nginx/error.log --add-module=../echo-ngin
x-module-master

6、启动新程序

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf
server {
  listen 80;
  server_name localhost;
  #charset koi8-r;
  #access_log logs/host.access.log main;
  location / {
    echo "mr";
  }

使用nginx t 检查配置文件内容

[root@localhost nginx-1.22.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is
ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is succes
sful

重载nginx
关闭防火墙

[root@localhost nginx-1.22.0]# systemctl stop firewalld
[root@localhost nginx-1.22.0]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost nginx-1.22.0]# vim /etc/selinux/config
[root@localhost nginx-1.22.0]# cat /etc/selinux/config
......
SELINUX=disabled
......
[root@localhost nginx-1.22.0]# nginx -s reload

二. location案例

location区段,通过指定模式来与客户端请求的URI相匹配

  • 功能:
    允许根据用户请求的URI来匹配定义的各个location,匹配时,此请求将被相应的location配置块中的配置所处理,例如做访问控制等功能
  • 语法:
    location [修饰符] pattern {……}
  • 修饰符
    = 精确匹配
    ~ 正则表达式模式匹配,区分大小写
    ~* 正则表达式模式匹配,不区分大小写
    ^~ 前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式
    定义命名location区段,这些区段客户端不能访问,只可以由内部产生的请求来访问,如
    try_files或者error_page等

增加一个location字段

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf

  server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /xq {
      echo "mr";
    }

用“=”精准匹配

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf
location = /xq {
echo "mr";
}
[root@localhost nginx-1.22.0]# nginx -s reload

~:表示指定的正则表达式要区分大小写

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf
  location ~ /xq$ {
    echo "mr";
  }
[root@localhost nginx-1.22.0]# nginx -s reload

当“=”和“~”同时存在时,此时时 = 优先于 ~

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf
location ~ /xq {
    echo "mr";
  }

    location = /xq {
      echo "mr";
  }
[root@localhost nginx-1.22.0]# nginx -s reload


~*:表示指定的正则表达式不区分大小写:

[root@localhost nginx-1.22.0]# vim /usr/local/nginx/conf/nginx.conf
location ~* ^/xq$ {
    echo "mr";
  }
[root@localhost nginx-1.22.0]# nginx -s reload

标签:log,--,平滑,module,升级,nginx,1.22,localhost
From: https://www.cnblogs.com/marymary/p/16786476.html

相关文章

  • Linux安装nginx
    1.进入nginx官网下载页面,下载Linux所需的压缩包文件。http://nginx.org/en/download.html   2.在安装nginx之前需要安装pcre,gcc,openssl,zlib。因为nginx依赖这......
  • nginx启动失败:Redirecting to /bin/systemctl restart nginx.service Failed to res
      解决:在/etc/init.d/下创建nginx文件作启动脚本1#!/bin/bash2#3#chkconfig:-85154#description:NginxisaWorldWideWebserver.5#process......
  • nginx 日志文件切割
    shell脚本cat_nginx_log.sh#!/bin/bash#nginx日志文件的存放路径logs_path='/app/openresty/nginx/logs'mv$logs_path/access.log$logs_path/access.$(date+%......
  • nginx 守护进程
    shell脚本catngx_daemon.sh#!/bin/bashnginxpid=$(ps-Cnginx--no-header|wc-l)if["$nginxpid"="0"];then#启动nginx/ap......
  • jenkins 升级
    1.下载war包  find/-namejenkins.war [root@localhostpipeline]#groupadddockergroupadd:“docker”组已存在gpasswd-a$USERdocker#将登陆用户加入......
  • nginx url地址重写与转发
    1. 去掉地址中的/api部分location/api/ws{      rewrite"^/api(.*)$"$1;   }2. /ws地址将转发http://47.119.131.185location/ws{      pr......
  • Spring Boot 2.3.x 升级至 2.4.x 遇到的那些事
    随着SpringBoot3.0需要Java17和SpringFramework6作为最低版本。计划逐步升级系统的SrpingBoot版本,以应对未来的趋势,当前系统SpringBoot版本是2.3.12,继续先升即到......
  • nginx配置——根据路由参数来设置对应响应方式
      location/{set$is_matched0;#是否有匹配的参数#正则判断url中携带的参数是否有匹配if($query_string~".*(?:^|\?|&)token=123"){set$is_ma......
  • CENTOS安装NGINX报错
    1特别是在CentOS7上安装Nginx,不确定你有什么样的错误(无法打开你的图像/图片),但刚刚在CentOS7上尝试过(大约10分钟前)(VagrantBox"CentOS-7.2-1.8T"),它通过......
  • centos7下Git版本升级
    1.下载需要的版本的git源码wgethttps://github.com/git/git/archive/v2.22.0.tar.gz2.安装编码依赖包yuminstallcurl-develexpat-develgettext-developenssl-dev......