Nginx正向代理

添加模块

由于nginx本身不支持https代理,这里需要引入第三方模块ngx_http_proxy_connect_module
以及还要下载openssl-1.1.1d
下载地址:openssl-1.1.1d
ngx_http_proxy_connect_module

#首先需要给nginx打上ngx_http_proxy_connect_module的补丁 具体细节查看github
patch -p1 < /usr/local/soft/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1014.patch
./configure -add-module=/usr/local/soft/ngx_http_proxy_connect_module --with-openssl=/usr/local/soft/openssl-1.1.1d --with-http_ssl_module
make & make install

添加代理配置

server {
        resolver 8.8.8.8;
        resolver_timeout 30s; 
        listen 82;
        location / {
                proxy_pass http://$http_host$request_uri;
                proxy_set_header Host $http_host;
                proxy_buffers 256 4k;
                proxy_max_temp_file_size 0;
                proxy_connect_timeout 30;
                proxy_cache_valid 200 302 10m;
                proxy_cache_valid 301 1h;
                proxy_cache_valid any 1m;
        }
    } 	

     server {
       resolver 8.8.8.8;   #dns解析地址
       listen 8888;          #代理监听端口
       proxy_connect;
       proxy_connect_allow            443 563;
       location / {
             proxy_pass https://$host$request_uri;     #设定https代理服务器的协议和地址
             proxy_set_header HOST $host;
             proxy_buffers 256 4k;
             proxy_max_temp_file_size 0k;
             proxy_connect_timeout 30;
             proxy_send_timeout 60;
             proxy_read_timeout 60;
             proxy_next_upstream error timeout invalid_header http_502;
 
       }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    } 

重启nginx,在电脑上配置代理地址

  • 配置地址 windows7:网络共享中心->internet -> 连接 -> 局域网设置 -> 代理服务器
    填入ip地址和端口号:如我的nginx地址是 192.168.93.128 端口号是 8888
    接下来打开浏览器就是用nginx进行转发访问了。
    可以在nginx查看日志 tail -f /usr/local/nginx/logs/access.log
# nginx 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×