nginx 正向代理内网其他主机上网
yum -y install gcc gcc-c++ pcre-devel pcre zlib-devel zlib openssl-devel openssl patch
cd /usr/src/soft
wget -c http://nginx.org/download/nginx-1.20.2.tar.gz
wget -c https://github.com/chobits/ngx_http_proxy_connect_module/archive/refs/heads/master.zip
unzip master.zip
tar -xf nginx-1.20.2.tar.gz
mv ngx_http_proxy_connect_module-master /usr/local/
cd nginx-1.20.2
#打上proxy_connect_rewrite补丁
patch -p1 < /usr/local/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1018.patch
./configure --prefix=/usr/local/nginx --add-module=/usr/local/ngx_http_proxy_connect_module-master --with-http_ssl_module
make
make install
nginx配置
#nginx配置
cat proxy.conf
server {
listen 8443;
resolver 114.114.114.114; #DNS
server_name localhost;
proxy_connect;
proxy_connect_allow 443 80;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_set_header Host $host;
proxy_pass $scheme://$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;
}
}
测试
测试
[root@www src]# curl -I --proxy 192.168.0.129:8443 https://www.baidu.com
HTTP/1.1 200 Connection Established
Proxy-agent: nginx
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Tue, 28 Nov 2023 07:15:38 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
[root@www src]#
[root@www src]#
[root@www src]#
[root@www src]#
[root@www src]#
[root@www src]#
[root@www src]# curl -I --proxy 192.168.0.129:8443 http://www.baidu.com
HTTP/1.1 200 OK
Server: nginx/1.20.2
Date: Tue, 28 Nov 2023 07:16:04 GMT
Content-Type: text/html
Content-Length: 277
Connection: keep-alive
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
windows代理设置
日志查看
tail -f /usr/local/nginx/logs/access.log
192.168.0.33 - - [28/Nov/2023:16:00:02 +0800] "CONNECT ss2.baidu.com:443 HTTP/1.1" 200 1337 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:02 +0800] "CONNECT ss3.baidu.com:443 HTTP/1.1" 200 1341 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:02 +0800] "CONNECT content-autofill.googleapis.com:443 HTTP/1.1" 504 569 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:02 +0800] "CONNECT b.bdstatic.com:443 HTTP/1.1" 200 2305 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:02 +0800] "CONNECT passport.baidu.com:443 HTTP/1.1" 200 12793 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:03 +0800] "CONNECT hpd.baidu.com:443 HTTP/1.1" 200 411 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:03 +0800] "CONNECT sp1.baidu.com:443 HTTP/1.1" 200 4973 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:03 +0800] "CONNECT sp1.baidu.com:443 HTTP/1.1" 200 4973 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:06 +0800] "CONNECT csdnimg.cn:443 HTTP/1.1" 200 39332 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"
192.168.0.33 - - [28/Nov/2023:16:00:11 +0800] "CONNECT 59.82.122.249:443 HTTP/1.1" 200 47912 "-" ""
------------end