nginx.conf配置文件:
#HTTP
server {
resolver 172.16.101.213; #指定DNS服务器IP地址
access_log /tmp/logs/nginx/access_proxy.log;
listen 8090;
location / {
proxy_pass http://$http_host$request_uri; #设定代理服务器的协议和地 址
proxy_set_header HOST $http_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 {
resolver 172.16.101.213; #指定DNS服务器IP地址
access_log /tmp/logs/nginx/access_proxy.log;
listen 8092;
location / {
proxy_pass https://$http_host$request_uri; #设定代理服务器的协议和地 址
proxy_set_header HOST $http_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;
}
}
#resolver从/etc/resolv.conf文件中获取
HTTP测试连接:
curl -X GET 'http://www.baidu.com/' --proxy 172.16.100.85:8090
tailf /tmp/logs/nginx/access_proxy.log -n 2
HTTPS测试连接:
curl -X GET 'http://www.baidu.com/' --proxy 172.16.100.85:8092
注意https的请求在GET时要修改成http,nginx将其正向代理出去时,会转成https。
nginx转发丢失'_'的问题,增加规则
配置nginx转发时,弹出未知身份的请求
解决办法:
转发时在nginx.conf中添加以下参数:
underscores_in_headers on;
nginx对于请求的header中有‘_’时,会自动忽略掉,该参数的用途是解除此项限制。