正向代理访问非80端口的服务
FROM centos:7ENV TZ=Asia/ShanghaiRUN cd /etc/yum.repos.d \&& curl -O http://mirrors.aliyun.com/repo/Centos-7.repo \&& yum makecache \&& yum -y install gcc g++ make tar openssl openssl-devel pcre-devel pcre rpm-build rpmdevtools lua lua-devel# https://openresty.org/download/openresty-1.15.8.3.tar.gzCOPY openresty-1.15.8.3.tar.gz /opt# https://github.com/chobits/ngx_http_proxy_connect_moduleCOPY ngx_http_proxy_connect_module.tgz /optRUN cd /opt && tar xaf openresty-1.15.8.3.tar.gz && tar xaf ngx_http_proxy_connect_module.tgz \&& cd /opt/openresty-1.15.8.3 \&& ./configure --prefix=/etc/openresty --with-http_stub_status_module --with-http_sub_module --with-http_auth_request_module --with-http_addition_module --add-module=/opt/ngx_http_proxy_connect_module \&& patch -d build/nginx-1.15.8/ -p 1 < /opt/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch \&& make -j "$(nproc)" && make install \&& mkdir -p /etc/openresty/nginx/conf/conf.d \&& ln -s /etc/openresty/nginx/sbin/nginx /usr/sbin/EXPOSE 80# vi nginx.conf: include /etc/openresty/nginx/conf/conf.d/*.confVOLUME /etc/openresty/nginx/conf/conf.dCMD ["nginx", "-g", "daemon off;"]
/etc/openresty/nginx/conf/conf.d/acdiost.conf
server {listen 80;# dns resolver used by forward proxyingresolver 8.8.8.8;# forward proxy for CONNECT requestproxy_connect;proxy_connect_allow all;proxy_connect_connect_timeout 10s;proxy_connect_read_timeout 10s;proxy_connect_send_timeout 10s;# forward proxy for non-CONNECT requestlocation / {if ($http_host ~ "(:(\d){5})$"){set_by_lua $port "local host = ngx.req.get_headers()[\"host\"];local port = string.sub(host,-5);return port ";set $passport $port ;proxy_pass http://$host:$passport$request_uri;}if ($http_host ~ "(:(\d){4})$"){set_by_lua $port "local host = ngx.req.get_headers()[\"host\"];local port = string.sub(host,-4);return port ";set $passport $port ;proxy_pass http://$host:$passport$request_uri;}if ($http_host ~ "(:(\d){3})$"){set_by_lua $port "local host = ngx.req.get_headers()[\"host\"];local port = string.sub(host,-3);return port ";set $passport $port ;proxy_pass http://$host:$passport$request_uri;}if ($http_host ~ "(:(\d){2})$"){set_by_lua $port "local host = ngx.req.get_headers()[\"host\"];local port = string.sub(host,-2);return port ";set $passport $port ;proxy_pass http://$host:$passport$request_uri;}if ($http_host !~ :){proxy_pass http://$host$request_uri;}proxy_pass http://$host;proxy_set_header Host $host;client_max_body_size 2000m;proxy_set_header terminal_id $http_terminal_id;proxy_set_header Host $host:$server_port;proxy_set_header X_Read_IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Host $host;proxy_set_header X-Forwarded-Server $host;proxy_set_header X-Forwarded-Proto $scheme;}# 测试lualocation /lua {default_type 'text/html';content_by_lua 'ngx.say("hello lua")';}}
测试结果
浏览器配置代理即可。谷歌浏览器需安装插件 Proxy SwitchyOmega
