汕尾海湾 发表于 2025-3-1 22:25:53

平滑升级旧版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目录下,如图所示:
https://i-blog.csdnimg.cn/direct/80670ee504ff401fb7dd162d4a40ae55.png
编译安装 luajit
将luajit2编译安装到/usr/local/luajit2中。
cd luajit2
# 编译
make
# 安装
make install PREFIX=/usr/local/luajit2
编译成功后如图所示:
https://i-blog.csdnimg.cn/direct/25a14a0b0ab044079c0425310385a34e.png
安装成功后如图所示:
https://i-blog.csdnimg.cn/direct/e8f16652229e418397d2a58e37b3a5a3.png
加入到情况变量中:
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
编译成功后如图所示:
https://i-blog.csdnimg.cn/direct/8c3e24b01a114de8b2f1e598f5e2c226.png
安装 lua-resty-core
cd lua-resty-core-0.1.27
# 安装
make install PREFIX=/usr/local
成功后如图所示:
https://i-blog.csdnimg.cn/direct/b4173db220a644d0b8d79d66926e0849.png
替换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
# 检察版本 打印下面的信息阐明升级成功:
https://i-blog.csdnimg.cn/direct/3aa1696346c84f36b68158d17aa5cd0c.png
在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连接:
https://i-blog.csdnimg.cn/direct/5176e3170dff4e24a94b9ec1c372e6ab.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 平滑升级旧版nginx,支持lua动态署理转发多个云平台VNC画面