有大神在ACL3.0上升级到NGINX1.25的案例吗?[阿里云服务器]

云服务器上是Alibaba Cloud Linux 3,安装的nginx 1.20最近看到1.25开始支持http3 比较喜欢研究新的东西,有点升级nginx的想法,想了解一下是否有人踩过坑。 准备明天开始在开发环境验证一下,开发环境是debian,可能会有点差异,所以欢迎有升级经验的大神指导一下。 此外,准备附带研究一下lua,动态封禁异常IP,虽然现在服务器性能业务还不大,未雨绸缪一下。

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
=====这是一个广告位,招租中,联系qq 78315851====
4 条回复 A 作者 M 管理员
  1. 我自己实贱了一下,基本步骤如下: 1.sudo dnf update 2.sudo yum -y install gcc automake autoconf libtool make wget 3.sudo yum -y install openssl openssl-devel 4.sudo yum -y install pcre pcre-devel 5.sudo yum -y install zlib zlib-devel 6.下载nginx1.25的源码并解压,进入目录 ./configure
    –prefix=/etc/nginx
    –user=nginx
    –group=nginx
    –sbin-path=/usr/sbin/nginx
    –conf-path=/etc/nginx/nginx.conf
    –error-log-path=/var/log/nginx/error.log
    –http-log-path=/var/log/nginx/access.log
    –pid-path=/var/run/nginx.pid
    –lock-path=/var/run/nginx.lock
    –http-client-body-temp-path=/var/cache/nginx/client_temp
    –http-proxy-temp-path=/var/cache/nginx/proxy_temp
    –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
    –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
    –http-scgi-temp-path=/var/cache/nginx/scgi_temp
    –with-file-aio
    –with-threads
    –with-http_addition_module
    –with-http_auth_request_module
    –with-http_dav_module
    –with-http_flv_module
    –with-http_gunzip_module
    –with-http_gzip_static_module
    –with-http_mp4_module
    –with-http_random_index_module
    –with-http_realip_module
    –with-http_secure_link_module
    –with-http_slice_module
    –with-http_ssl_module
    –with-http_stub_status_module
    –with-http_sub_module
    –with-http_v2_module
    –with-http_v3_module
    –with-mail
    –with-mail_ssl_module
    –with-stream
    –with-stream_realip_module
    –with-stream_ssl_module
    –with-stream_ssl_preread_module–with-stream_ssl_module
    –with-stream_ssl_preread_module 7.make 编译一切正常 8.备份nginx配置及执行文件 sudo make install 这个时候运行nginx -V就会发现版本已经升级 [root@daymele nginx]# nginx -V nginx version: nginx/1.25.0 built by gcc 10.2.1 20200825 (Alibaba 10.2.1-3.5 2.32) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled configure arguments: –prefix=/etc/nginx –user=nginx –group=nginx –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –with-file-aio –with-threads –with-http_addition_module –with-http_auth_request_module –with-http_dav_module –with-http_flv_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp4_module –with-http_random_index_module –with-http_realip_module –with-http_secure_link_module –with-http_slice_module –with-http_ssl_module –with-http_stub_status_module –with-http_sub_module –with-http_v2_module –with-http_v3_module –with-mail –with-mail_ssl_module –with-stream –with-stream_realip_module –with-stream_ssl_module –with-stream_ssl_preread_module

  2. 在升级nginx之前,您需要先确保您的服务器硬件和软件环境支持http3。如果您已经满足这些要求,您可以开始进行nginx升级。

    以下是升级nginx的一些步骤和建议:

    1.备份您的nginx配置文件和网站文件,以防升级过程中出现问题。

    2.下载最新的nginx版本,并解压缩到您的服务器上。

    3.比较旧版本的nginx配置文件和新版本的配置文件,以查看有哪些更改。您可以在官方文档中找到这些更改的详细信息。

    4.逐步升级您的网站。您可以在旧版本的nginx中运行新版本的网站,以确保新版本不会破坏您的网站。

    5.测试您的nginx配置文件和新版本的网站。您可以使用一些工具来测试您的网站,例如:ab(ApacheBench)和wrk。

    6.在生产环境中进行测试,以确保新版本的nginx可以正常运行。

    关于使用lua进行动态封禁异常IP,以下是一些建议:

    1.使用lua可以方便地编写脚本来处理nginx的请求和响应。您可以使用lua来检查客户端IP地址,并根据需要对其进行封禁。

    2.在nginx配置文件中添加lua代码。您可以使用lua-nginx-module来添加lua代码到nginx配置文件中。

    3.编写lua脚本来处理异常IP地址。您可以使用lua中的if语句和循环来检查IP地址,并根据需要对其进行封禁。

    4.测试您的lua脚本。您可以使用一些工具来测试您的lua脚本,例如:ab(ApacheBench)和wrk。

    5.在生产环境中进行测试,以确保您的lua脚本可以正常运行。

    希望这些建议可以帮助您升级nginx和使用lua进行动态封禁异常IP。祝您成功!

  3. 云服务器上安装的nginx版本与更新到1.25版本的步骤可能因为不同的环境和配置情况而略有不同,但普遍来说,升级nginx的过程比较简单,您只需要完成以下步骤即可:

    1.备份原有的nginx

    在升级nginx之前,您需要首先备份原有的nginx配置文件和网站文件。可以将这些文件复制到其他地方,以防升级出现问题时能够恢复。

    2.下载新版本的nginx

    您可以到nginx官网上下载最新版本的nginx。在下载时,建议选择最稳定的版本。下载结束后,解压缩到任意目录。

    3.编译安装新版本的nginx

    进入解压后的nginx目录,执行 make 和 make install 命令。如下所示:

    ./configuremakemake install

    4.备份新的nginx.conf文件

    在 make install 命令执行完毕之后,新版本的nginx就已经安装成功了。此时,您需要备份新版本的nginx.conf文件。可将其复制到其他地方,以防配置错误导致访问不到网站。

    5.修改配置文件

    修改新版本nginx.conf文件中的 listen 属性,将其修改为需要监听的端口号,例如:

    listen 80;

    如果需要支持http3,在 nginx.conf 中添加以下配置:

    listen 443 quic reuseport;ssl_certificate /path/to/cert;ssl_certificate_key /path/to/key;

    其中,/path/to/cert 代表SSL证书的路径,/path/to/key 代表 SSL证书密钥的路径。如果您还没有证书,可以到阿里云SSL证书服务中申请。

    6.重启nginx

    修改nginx配置文件后,需要将新版本的nginx重启。可以先使用 nginx -t 命令检查新的配置文件是否有错误,如果没有错误,则使用 nginx -s reload 命令重启nginx。

    至于您提到的动态封禁异常IP的功能,可以借助nginx的 geoip 模块实现。首先,您需要在nginx中安装geoip模块,然后下载GeoLite2-City数据集。下载完成后,将GeoLite2-City.mmdb文件复制到任意目录。接下来,在您的nginx.conf中添加以下配置:

    http {    geoip2 /path/to/GeoLite2-City.mmdb {        $geoip2_metadata_country_iso_code country iso_code;        $geoip2_metadata_country_names_en country names.en;        $geoip2_metadata_city_names_en city names.en;    }    map $geoip2_metadata_country_iso_code $allowed_country {        default yes;        CN no; #禁止中国IP访问    }    map $geoip2_metadata_city_names_en $allowed_city {        default yes;        "Beijing" no; #禁止北京IP访问    }    ...    server {        ...        if ($allowed_country = no) {            return 403; #拒绝访问        }        ...        if ($allowed_city = no) {            return 403; #拒绝访问        }        ...    }}

    上述配置中,$allowed_country 和 $allowed_city 分别表示当前访问的用户所在的国家和城市,您可以根据自己的需求进行修改。如果需要禁止访问,就将 $allowed_country 和 $allowed_city 的值设为 no,否则为 yes。

  4. 1升级 Nginx 的步骤如下:

    1.备份原有的 Nginx 配置文件和数据文件,在升级之前一定要备份,以防意外情况。

    2.升级 Nginx 软件包到最新版本,您可以通过以下命令来检查是否有新版本可用,然后使用 apt-get 命令进行升级:

    Copy sudo apt-get update sudo apt-get upgrade nginx 3.检查 Nginx 配置文件是否与新版本兼容,如果配置文件中使用了已弃用或已删除的模块或指令,则可能会导致升级后出现问题。可以查看 Nginx 官方文档,了解新版本的更改和兼容性问题。

    4.重新启动 Nginx 服务,如果一切正常,则应该可以顺利启动 Nginx 服务。

    关于 Lua,您可以通过以下步骤在 Nginx 中使用 Lua:

    1.安装 OpenResty,OpenResty 是一个基于 Nginx 的 Web 应用服务器,它集成了 Lua 环境和其他一些模块,可以方便地在 Nginx 中使用 Lua。

    2.编写 Lua 脚本,您可以使用 Lua 编写更复杂的业务逻辑,例如动态封禁异常 IP。

    3.在 Nginx 配置文件中加载 Lua 脚本,您可以使用 lua_code_cache 指令来控制 Lua 代码的缓存行为,并使用 content_by_lua 指令将 Lua 代码嵌入到 Nginx 的请求处理流程中。

    下面是一个示例 Nginx 配置文件,演示了如何加载 Lua 脚本:

    Copy http { lua_package_path “/path/to/lua/?.lua;;”; server { listen 80; location / { content_by_lua_file /path/to/lua/script.lua; } } } 其中,lua_package_path 指令用于设置 Lua 脚本的搜索路径,content_by_lua_file 指令用于加载指定的 Lua 脚本文件。

  5. 升级Nginx到最新版本是一个好的想法,因为新版本通常会带来更好的性能和更多的功能。但是,在升级之前,您应该确保您的应用程序和服务器环境都能够支持新版本的Nginx,以避免出现不必要的问题。

    在升级之前,建议您备份现有的Nginx配置文件和相关的数据。然后,您可以使用适合您的操作系统的软件包管理器来安装新版本的Nginx。对于Debian系统,您可以使用apt-get命令来安装最新版本的Nginx。例如,您可以执行以下命令:

    sudo apt-get update sudo apt-get install nginx 安装完成后,您可以将备份的Nginx配置文件复制回新的安装目录,并根据需要进行修改。

    如果您想使用HTTP3协议,您需要确保您的服务器和客户端都支持它。在Nginx中启用HTTP3协议需要使用特定的模块,例如ngx_http_quic_module。您可以通过在Nginx配置文件中添加以下行来启用HTTP3协议:

    listen 443 quic; 至于Lua模块,Nginx提供了ngx_http_lua_module模块,它允许您使用Lua脚本进行高级自定义。您可以使用Lua脚本来动态封锁异常IP等操作。要使用ngx_http_lua_module模块,您需要在编译Nginx时添加–with-http_lua_module选项。安装完成后,您可以在Nginx配置文件中使用Lua脚本,例如:

    location / { access_by_lua_block { — 在这里编写Lua脚本 } } 总之,升级Nginx和使用Lua脚本都可以提高您的服务器性能和安全性。但是,在进行这些操作之前,请确保您了解相关的知识,并备份您的数据和配置文件,以避免出现不必要的问题。