搭建Nginx正向代理服务

                                                                                                                             

目录 

安装环境准备:

安装成功后,配置nginx正向代理:

在环境变量里添加代理:


 

安装环境准备:

首先下载这一模块:https://github.com/chobits/ngx_http_proxy_connect_module到服务器,然后准备nginx环境

yum -y install pcre-devel zlib-devel gcc gcc+c++ make openssl-devel pcre-devel  zlib-devel patch  

tar xf nginx-1.6.0.tar.gz

unzip /root/ngx_http_proxy_connect_module-master.zip

cd  /root/nginx-1.6.0/

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

./configure --add-module=/root/ngx_http_proxy_connect_module-master/ngx_http_proxy_connect_module

make &&  make install

安装成功后,配置nginx正向代理:

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

 

server {

        listen 88;                #监听端口

        resolver 183.60.82.98;   #dns解析地址

        server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

             proxy_pass https://$host$request_uri;     #设定http代理服务器的协议和地址

             proxy_set_header HOST $host;

             proxy_buffers 256 4k;

             proxy_max_temp_file_size 0k;

             proxy_connect_timeout 30;

             proxy_send_timeout 60;

             proxy_read_timeout 60;

             proxy_next_upstream error timeout invalid_header http_502;

            #root   html;

            #index  index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

 

    }

 

 

 

server {

       resolver 8.8.8.8;   #dns解析地址

       listen 89;          #代理监听端口

       proxy_connect;

       proxy_connect_allow            443 563;

       location / {

             proxy_pass https://$host$request_uri;     #设定https代理服务器的协议和地址

             proxy_set_header HOST $host;

             proxy_buffers 256 4k;

             proxy_max_temp_file_size 0k;

             proxy_connect_timeout 30;

             proxy_send_timeout 60;

             proxy_read_timeout 60;

             proxy_next_upstream error timeout invalid_header http_502;

 

       }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

    }  }

配置文件配置好之后wq回车保存,然后重启nginx即可,最后进行下面操作

在环境变量里添加代理:

vim  /etc/profile

...

...

#export https_proxy=正向代理IP:端口

export https_proxy=192.168.3.17:89

对于另一种方式是临时代理:(此方式不需要加环境变量)

#curl -i  --proxy 代理IP:端口      要访问域名

curl -i  --proxy 192.168.3.17:89      www.baidu.com

你可能感兴趣的:(Linux,运维开发,nginx,代理模式,linux,nginx反向代理,运维)