Nginx正向代理http请求

1.简单的正向代理

#正向代理http
 server {
   #     access_log /home/bingchenglin/logs/nginx/access.log;   日志一般最上面配置全局         
        listen 8082;
        location / { 

               resolver 8.8.8.8;#DNS解析 可以用这个
                proxy_pass $scheme://$http_host$request_uri;
                proxy_buffers   256 4k;
                 proxy_max_temp_file_size 0k;
       }
}
该访问会默认访问80端口 有些网址不是80端口或者图片不能加载

2.通过加入Lua模块对非80端口进行访问

这里有个地址:https://www.cnblogs.com/aoeiuv/p/6856056.html

找到的一个配置文件 

if ($http_host ~ "(:(\d){4})$"){

   set_by_lua $port "    

   local host = ngx.req.get_essay-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_essay-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_essay-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;

}

 

你可能感兴趣的:(Linux,Nginx)