欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Nginx代理上網的方法

 更新時間:2019年05月13日 09:08:34   作者:TMaize''Blog  
這篇文章主要介紹了使用Nginx代理上網的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

我一般都是使用 nginx 做反向代理 tomcat 和其他應用的,其實 nginx 也是支持正向代理的

所謂正向代理就是內網用戶通過網關訪問外部資源,就是電腦上網時瀏覽器設置下 http 代理地址訪問互聯(lián)網

而反向代理就是外部用戶通過網關訪問內網資源,通俗講就是,你的網站跑在內網的 8080 端口,別人能夠通過 80 端口來訪問它

http 代理配置

# 正向代理上網
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 已經變化了,說明生效了

然而訪問 https 網站卻打不開,這是由于原生 nginx 只支持 http 正向代理,為了 nginx 支持 https 正向代理,可以打 ngx_http_proxy_connect_module 補丁+ ssl 模塊支持

添加 https 代理模塊

這里需要重新編譯 nginx,需要查看當前 nginx 的版本和編譯選項,然后去官網下載同版本的 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 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite

在原有配置后追加模塊,make 后注意不要 install

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/

更改配置文件如下,然后啟動服務

# 正向代理上網
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;
  }
}

總結

代理感覺不是很穩(wěn)定,有時候會打不開,尤其是 https 網站。訪問國外網站千萬不要這樣搞,這里只是為了熟悉下 nginx 的正向代理功能

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論