nginx實戰(五) 正向代理支持https
阿新 • • 發佈:2018-10-19
pat for lis erer -m request one resolv sent 前言
正向代理,是指內網用戶設置代理服務器的IP及端口實現訪問公網的訪問方式(https://baike.baidu.com/item/正向代理/9524799)
nginx 自帶的proxy 也可以實現正向代理功能,但是不支持https ,所以我選用了ngx_http_proxy_connect_module 模塊
添加ngx_http_proxy_connect_module 模塊
nginx 基礎環境編譯見nginx實戰(一)
yum -y install patch git clone https://github.com/chobits/ngx_http_proxy_connect_module.git cd openresty-1.13.6.2 ./configure --add-module=../ngx_http_proxy_connect_module patch -d build/nginx-1.13.6/ -p 1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1014.patch gmake && gmake install
代理配置
cat>proxy_connect.conf<<EOF log_format proxy ‘$remote_addr - $remote_user [$time_local] "$request" - $http_host ‘ ‘status:$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; server { listen 8080; server_name localhost; #設置dns 地址 resolver 202.96.209.133; resolver_timeout 30s; set $proxy_remote_address ""; set $proxy_local_address ""; proxy_connect; proxy_connect_connect_timeout 10s; proxy_connect_read_timeout 150; proxy_connect_send_timeout 10s; proxy_connect_send_lowat 0; proxy_connect_address $proxy_remote_address; proxy_connect_bind $proxy_local_address; access_log logs/proxy.access.log proxy; location / { proxy_pass http://$http_host; proxy_set_header Host $host; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } EOF
客戶端代理設置
?
linux
cat >>/etc/profile<<EOF
printf -v no_proxy ‘%s,‘ 172.17.0.{1..255}; ## 生成內網所有ip
http_proxy=http://172.17.0.16:8080
https_proxy=http://172.17.0.16:8080
no_proxy="${no_proxy%,},localhost,127.0.0.1,localaddress,.localdomain.com" ## 排除本地ip
export http_proxy https_proxy no_proxy
EOF
docker 代理設置
vim /lib/systemd/system/docker.service
Environment="HTTP_PROXY=http://172.17.0.16:8080/" "HTTPS_PROXY=https://172.17.0.16:8080/"
參考
https://github.com/chobits/ngx_http_proxy_connect_module
nginx實戰(五) 正向代理支持https