nginx正向代理
服务端配置
1、安装nginx
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel wget pcre pcre-devel git git clone https://github.com/chobits/ngx_http_proxy_connect_module.git wget http://nginx.org/download/nginx-1.14.2.tar.gz tar -xzvf nginx-1.14.2.tar.gz cd nginx-1.14.2/ patch -p1 <../ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch #补丁 ./configure --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_http_proxy_connect_module make && make install
2、配置
mkdir -p /usr/local/nginx/conf/conf.d/ vim /usr/local/nginx/conf/nginx.conf user nobody; #注释删掉 include /usr/local/nginx/conf/conf.d/*.conf; #添加90端口的配置文件
vim /usr/local/nginx/conf/conf.d/test.conf server { listen 90; #端口 server_name 10.0.0.43; #一般写dns服务器 也可以直接写ip 本机ip resolver 223.5.5.5; proxy_connect; proxy_connect_allow 443 563; # https proxy_connect_connect_timeout 10s; proxy_connect_read_timeout 10s; proxy_connect_send_timeout 10s; location / { proxy_pass http://$host; proxy_set_header Host $host; } } /usr/local/nginx/sbin/nginx #启动nginx ss -lntp|grep nginx #只剩90端口
客服端配置
1、全局的代理设置:
vim /etc/profile export http_proxy=http://10.0.0.43:90 #服务端ip export https_proxy=http://10.0.0.43:90 #服务端ip export ftp_proxy=http://10.0.0.43:90 #服务端ip source /etc/profile
2、yum的代理设置:
vim /etc/yum.conf proxy=http://http://10.0.0.43:90
3、wget的代理设置:
vim /etc/wgetrc http_proxy=http://10.0.0.43:90 ftp_proxy=http://10.0.0.43:90
注释
vim /etc/resolve.conf #nameserver 223.5.5.5 #nameserver 223.6.6.6
4.测试代理
方法1
curl ‐I ‐‐proxy 10.0.0.44:90 http://www.baidu.com curl ‐I ‐‐proxy 10.0.0.44:90 https://www.baidu.com
方法2
使用火狐浏览器
滑到最下面
访问一下百度
然后关闭nginx,之后在访问一下百度
pkill -9 nginx
说明成功了