当前位置: 首页 > news >正文

平滑升级旧版nginx,支持lua动态代理转发多个云平台VNC画面

nginx是部署在华为欧拉的docker容器中,版本是2203sp1.x86_64

查看旧版nginx的版本与编译配置信息:

nginx -V

nginx version: nginx/1.24.0
built by gcc 10.3.1 (GCC)
built with OpenSSL 1.1.1wa 16 Nov 2023
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt=‘-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fPIC -D_FORTIFY_SOURCE=2 -O2 -Wtrampolines -fsigned-char’ --with-ld-opt=‘-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack’ --add-module=/usr/lib64/nginx/modules/nginx_upstream_check_module-master

根据版本信息,下载好升级所需的组件:
nginx 1.24.0
lua-nginx-module 0.10.25
luajit2 v2.1-20231117
ngx_devel_kit 0.3.3
lua-resty-core 0.1.27

以上版本是依据 Openresty 1.25.3的依赖列表配置的,想找1.24版本但是没有找到,所以就找了一个临近版。

注意:lua-nginx-module 从 0.10.16 开始部分函数被拆分到 lua-resty-core 中,例如 ngx.req.get_uri_args(),所以需要安装 lua-resty-core,同时 lua-resty-core 对 lua-nginx-module 的版本有要求需要一一对应,对应关系可以在 lib\resty\core\base.lua 中找到。

将下载好的文件全部解压到服务器的root目录下,如图所示:
在这里插入图片描述
编译安装 luajit

将luajit2编译安装到/usr/local/luajit2中。

cd luajit2
# 编译
make
# 安装
make install PREFIX=/usr/local/luajit2

编译成功后如图所示:
在这里插入图片描述
安装成功后如图所示:
在这里插入图片描述
加入到环境变量中:

export LUAJIT_LIB=/usr/local/luajit2/lib
export LUAJIT_INC=/usr/local/luajit2/include/luajit-2.1

编译 nginx

cd nginx-1.24.0
# 编译参数配置
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fPIC -D_FORTIFY_SOURCE=2 -O2 -Wtrampolines -fsigned-char' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack' --add-module=/usr/lib64/nginx/modules/nginx_upstream_check_module-master --with-ld-opt='-lpcre -Wl,-rpath,/usr/local/luajit2/lib' --add-module=/root/ngx_devel_kit-0.3.3 --add-module=/root/lua-nginx-module-0.10.25
# 编译
make

编译成功后如图所示:
在这里插入图片描述

安装 lua-resty-core

cd lua-resty-core-0.1.27
# 安装
make install PREFIX=/usr/local

成功后如图所示:
在这里插入图片描述

替换nginx可执行文件

备份旧的二进制程序(旧程序的路径可通过编译配置信息的--sbin-path获知):

mv /usr/sbin/nginx /usr/sbin/nginx.bak

将新生成的二进制程序替换旧的(新生成的二进制程序在objs目录中):

cp /root/nginx-1.24.0/objs/nginx /usr/sbin/nginx

查看nginx版本信息,执行nginx自检命令,查看是否升级成功:

nginx -V # 查看版本

打印下面的信息说明升级成功:
在这里插入图片描述

在nginx中引用 lua-resty-core 模块

修改nginx配置文件,在http全局配置添加lua配置:

lua_package_path "/usr/local/lib/lua/?.lua;;"; # 设置lua模块
lua_shared_dict dynamic_upstreams 1m; # 共享字典 有需要可以加上

修改之前的nginx wss配置文件,加上lua脚本(业务说明:我需要通过nginx lua动态代理来连接不同第三方云平台虚拟机vnc,从而避免前端的跨域及证书问题):

location /ws/vnc {
    set $target_upstream '';
    access_by_lua_block {
        local args = ngx.req.get_uri_args()
        local target = args["target"]
        if not target then
            ngx.status = ngx.HTTP_BAD_REQUEST
            ngx.say("Missing 'target' parameter")
            ngx.exit(ngx.HTTP_BAD_REQUEST)
        end
        ngx.var.target_upstream = target
    }
    proxy_ssl_verify off;
    proxy_pass $target_upstream;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
    proxy_set_header Sec-WebSocket-Protocol $http_sec_websocket_protocol;
    proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
    proxy_read_timeout 600s;
    proxy_send_timeout 600s;
}

保存配置后,重启nginx服务:

systemctl restart nginx

前端组织url访问/ws/vnc,成功实现nginx lua动态转发VNC连接:
在这里插入图片描述

相关文章:

  • 网站开发如何入门关键一招
  • 利用万网做网站肇庆网站建设制作
  • 自由型网站永久免费的电销外呼系统
  • 管理系统前端模板/seo推广招聘
  • 利用帝国软件如何做网站/推广方案100个
  • 仿网站源码/网络销售平台排名前十
  • 9. centos 离线安装docker
  • MES生产制造执行管理系统(源码+配套文档)
  • 解决IDEA使用Ctrl + / 注释不规范问题
  • 使用机器学习进行土地覆盖分类
  • 游戏引擎学习第122天
  • vLLM专题(十四)-自动前缀缓存
  • windows、Linux 设置 SSH 密钥并连接到 GitHub
  • Flash-03
  • ARM Cortex-M处理器中的MSP和PSP
  • 双周报Vol.66: String模式匹配增强、while条件支持使用 is 表达式、新增IDE安装器...多项核心技术更新!
  • 前端包管理工具进化论:npm vs yarn vs pnpm 深度对比
  • 【软考】计算机软件著作权的保护期
  • 高级系统架构师--第十章:计算机网络
  • 【初阶数据结构】链表的柔光之美
  • 软件工程----瀑布模型
  • 【Python模块】——pymysql
  • 华为hcia——Datacom实验指南——二层交换原理
  • 一键导出数据库表到Excel
  • AI人工智能之机器学习sklearn特征选择
  • [原创](Modern C++)现代C++的关键性概念: 流迭代器std::istream_iterator的优秀用法