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