欢迎各位来投稿,投稿邮箱 admin@veimx.com 欢迎各位爱好PHP,linux的朋友们加入我们

Nginx 实现http 反向代理 https的网站

Linux spade 457℃

下面是实现普通的反向代理 通过 proxy_pass 配置

server {
   listen 80;
   resolver 9.9.9.9;
 
   location / {
   proxy_pass http://www.qq.com;
   proxy_ignore_headers   Expires Cache-Control;
   proxy_set_header        Host            $host:$server_port;
   proxy_set_header        X-Real-IP       $remote_addr;
   proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header        X-Forwarded-Proto $scheme;
  }
}

 

废话不多说 现在我们来进入 实战

需要安装第三方模块ngx_http_proxy_connect_module,只支持较低版本nginx。

https://github.com/chobits/ngx_http_proxy_connect_module

0x101 安装

#yum -y install openssl openssl-devel git  wget patch gcc gcc-c++ make

#git clone https://github.com/chobits/ngx_http_proxy_connect_module.git

#wget http://nginx.org/download/nginx-1.9.2.tar.gz

# tar -xzvf nginx-1.9.2.tar.gz $ cd nginx-1.9.2/

# patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect.patch

# ./configure —add-module=/root/ngx_http_proxy_connect_module –with-http_ssl_module

# make && make install

0x102 配置

server {
     listen                         81;
 
     # dns resolver used by forward proxying
     resolver                       9.9.9.9;
 
     # forward proxy for CONNECT request
     proxy_connect;
     proxy_connect_allow            443 563;
     proxy_connect_connect_timeout  10s;
     proxy_connect_read_timeout     10s;
     proxy_connect_send_timeout     10s;
 
     # forward proxy for non-CONNECT request
     location / {
         proxy_pass https://www.baidu.com;
         proxy_set_header Host www.baidu.com;
     }
 }

 

0x103 测试

http://119.29.102.139:81/



转载请注明:巴蜀风博客-个人爱好博客-你的私人博客 » Nginx 实现http 反向代理 https的网站

喜欢 (0)or分享 (0)