http 代理配置
#?正向代理上網(wǎng) server?{ ??listen????38080; ??#?解析域名 ??resolver???8.8.8.8; ??location?/?{ ????proxy_pass?$scheme://$http_host$request_uri; ??} }
瀏覽器配置下代理 ip 和端口,然后訪問 http://www.ip138.com ,可以發(fā)現(xiàn) ip 已經(jīng)變化了,說明生效了
然而訪問 https 網(wǎng)站卻打不開,這是由于原生 nginx 只支持 http 正向代理,為了 nginx 支持 https 正向代理,可以打 ngx_http_proxy_connect_module 補丁+ ssl 模塊支持
添加 https 代理模塊
這里需要重新編譯 nginx,需要查看當前 nginx 的版本和編譯選項,然后去官網(wǎng)下載同版本的 nginx 源碼進行重新編譯
/usr/local/nginx/sbin/nginx?-v
wget?http://nginx.org/download/nginx-1.15.12.tar.gz tar?-zxvf?nginx-1.15.12.tar.gz
下載模塊 ngx_http_proxy_connect_module
git?clone?https://github.com/chobits/ngx_http_proxy_connect_module
打補丁,對 nginx 源碼修改,這一步很重要,不然后面的 make 過不去
patch?-d?/root/nginx-1.15.12/?-p?1?<p>在原有配置后追加模塊,make 后注意不要 install</p><pre class="brush:bash;">cd?/root/nginx-1.15.12/ ./configure?--with-http_stub_status_module?--with-http_ssl_module?--with-file-aio?--with-http_realip_module?--add-module=/root/ngx_http_proxy_connect_module/ make mv?/usr/local/nginx/sbin/nginx?/usr/local/nginx/sbin/nginx.bak cp?/root/nginx-1.15.12/objs/nginx?/usr/local/nginx/sbin/
更改配置文件如下,然后啟動服務(wù)
#?正向代理上網(wǎng) server?{ ??listen????38080; ??#?解析域名 ??resolver???8.8.8.8; ??#?ngx_http_proxy_connect_module ??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?$scheme://$http_host$request_uri; ??} }
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END