nginx正向代理的配置
http 和 https
server {
resolver 114.114.114.114; #指定DNS服务器IP地址
listen 80;
location / {
proxy_pass http://$host$request_uri; #设定代理服务器的协议和地址 (这里不用修改)
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
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 {
resolver 114.114.114.114; #指定DNS服务器IP地址
listen 443;
location / {
proxy_pass https://$host$request_uri; #设定代理服务器的协议和地址
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
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;
}
}
Linux客户端访问测试
[root@oa_test ~]# curl -I --proxy 10.10.24.66:8090 www.baidu.com
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 05 Jul 2022 07:55:15 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: "575e1f72-115"
Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT
Pragma: no-cache
设置Linux客户端全局代理
vim /etc/profile
export http_proxy='10.10.24.66:8090'
export http_proxy='10.10.24.66:443'
export ftp_proxy='10.10.24.66:8090'
source /etc/profile
[root@oa_test ~]# curl -I www.baidu.com:443
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 05 Jul 2022 07:59:12 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: "575e1f72-115"
Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT
Pragma: no-cache
[root@oa_test ~]# curl -I www.baidu.com:80
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Tue, 05 Jul 2022 07:59:22 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: "575e1f72-115"
Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT
Pragma: no-cache
如果不支持https 请参考文档增加模块即可
https://blog.csdn.net/xiaohuai0444167/article/details/105753108/?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0–blog-119714416.pc_relevant_multi_platform_whitelistv1&spm=1001.2101.3001.4242.1&utm_relevant_index=3