nginx正向代理
安装nginx
再下载补丁zip包,否则做不了https
补丁包链接:git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
进入安装包解压目录
cd /usr/local/nginx-1.18.0
看清楚自己存放的路径
# patch -p1 < /usr/local/ngx_http_proxy_connect_module/patch/proxy_connect.patch
安装补丁(根据自己需要添加别的模块)
# ./configure --add-module=/usr/local/ngx_http_proxy_connect_module
如果是安装好之后再添加模块只需要make就行
# make
第一次安装的话就需要
# make install
配置文件如下:
server {
listen 9998;
resolver 223.5.5.5 223.6.6.6 114.114.114.114;
location / {
proxy_pass http://$host$request_uri;
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;
}
}
server {
listen 9999;
resolver 223.5.5.5 223.6.6.6 114.114.114.114;
proxy_connect;
proxy_connect_allow all;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass https://$host$request_uri;
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;
}
}
测试命令:
# curl -I --proxy 192.168.0.10:9999 http://www.baidu.com #测试443
# curl -I --proxy 192.168.0.10:9998 http://www.baidu.com #测试80
也可以在环境变量里添加代理进行测试:
vim /etc/profile
export http_proxy=192.168.0.227:9998
export https_proxy=192.168.0.227:9999
source /etc/profile #使配置生效
curl -i www.baidu.com #测试访问