下载
https://nginx.org/download/nginx-1.20.2.tar.gz
https://github.com/chobits/ngx_http_proxy_connect_module/archive/refs/tags/v0.0.5.tar.gz
安装依赖
yum -y install make gcc openssl openssl-devel pcre-devel zlib zlib-devel
打patch
patch -p1 < /nginx/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
./configure --add-module=/nginx/ngx_http_proxy_connect_module
make && make install
nginx配置文件
cd /usr/local/nginx/
#gzip on;下添加
vim conf/nginx.conf
#gzip on;
#正向代理转发http请求
server {
#指定DNS服务器IP地址
resolver 114.114.114.114;
#监听80端口,http默认端口80
listen 80;
#服务器IP或域名
server_name localhost;
#正向代理转发http请求
location / {
proxy_pass http://$host$request_uri;
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;
}
}
#正向代理转发https请求
server {
#指定DNS服务器IP地址
resolver 114.114.114.114;
#监听443端口,https默认端口443
listen 443;
#正向代理转发https请求
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 http://$host;
proxy_set_header Host $host;
}
}
验证
测试访问baidu
curl -I http://www.baidu.com/ -v -x 127.0.0.1:80
curl -I https://www.baidu.com/ -v -x 127.0.0.1:443
配置yum使用代理更新
#追加配置
vim /etc/yum.conf
proxy=http://192.168.0.20:80 #nginx正向代理服务器的地址
proxy=ftp://192.168.0.20:80 #nginx正向代理服务器的地址
配置wget使用代理下载
#追加配置
vim /etc/wgetrc
http_proxy=192.168.0.20:80 #nginx正向代理服务器的地址
http_proxy=192.168.0.20:443 #nginx正向代理服务器的地址
Linux全局配置
#追加配置
vim /etc/profile
http_proxy=192.168.0.20:80
https_proxy=192.168.0.20:443
ftp_proxy=192.168.0.20:443
export http_proxy
export https_proxy
export ftp_proxy
# 加载配置
source /etc/profile
windows配置