nginx正向代理https
需求
当出现下述情形时,我们需要使用正向代理:
我们的client不能直接访问到服务器,倒是其他的client可以访问,且我们的client到OtherClient
的网络是通的。
如何搭建正向代理
-
使用nginx
-
使用squid
-
。。。其他的方式
注
本人搭建的方式为nginx
使用nginx搭建正向代理
材料
-
nginx支持CONNECT的patch : git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
-
nginx的各个依赖—上nginx.org中找寻nginx的依赖相关的问题
编译过程
-
cd /path/to/nginx
-
patch -p1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1014.patch
-
./configure --add-module=/path/to/ngx_http_proxy_connect_module
-
make & make install : 默认会安装到/usr/local/nginx目录
修改配置
#resolver 119.29.29.29;
resolver 8.8.8.8;
server {
listen 6666;
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass http://$host;
proxy_set_header Host $host;
}
}
启动nginx
sbin/nginx -c conf/nginx.conf
client链接otherClient(chrome)
-
使用Proxy SwitchySharp,设置Manual Configuration
-
http proxy = otherClient ip
-
Port = 6666
-
勾上Use the same proxy server for all protocols
使用该配置
之后在chrome中的所有请求都经过该代理去访问服务