时间:2021-07-01 10:21:17 帮助过:4人阅读
这两天在研究nginx的正向代理,想通过nginx搭建一个http代理服务器,网站找到了这篇文章(http://www.cnblogs.com/inteliot/archive/2013/01/11/2855907.html):
server {
resolver 8.8.8.8;
resolver_timeout 5s;
listen 0.0.0.0:8080;
access_log /home/reistlin/logs/proxy.access.log;
error_log /home/reistlin/logs/proxy.error.log;
location / {
proxy_pass $scheme://$host$request_uri;
proxy_set_header Host $http_host;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0;
proxy_connect_timeout 30;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;#allow 127.0.0.1;
#deny all;} }
resolver 8.8.8.8; resolver_timeout 5s;
proxy_pass $scheme://$host$request_uri; proxy_set_header Host $http_host;
proxy_buffers 256 4k; proxy_max_temp_file_size 0; proxy_connect_timeout 30;
proxy_cache_valid 200 302 10m; proxy_cache_valid 301 1h; proxy_cache_valid any 1m;
"CONNECT www.google.com:443 HTTP/1.1" 400
作者写的很棒,不过,我在配置过程中,遇到问题,就是通过配置的代理访问页面都报404(我的nginx版本:1.2),后来我发现需要改下proxy_pass:
proxy_pass $scheme://$host$request_uri;改成:
proxy_pass $scheme://$http_host$request_uri;
这样就可以了,另外我加上了ip的限制,大家有需要可以将上面的注释打开就行:
allow 127.0.0.1; deny all;
head info:{content-type=application/x-www-form-urlencoded; charset=UTF-8, c content-length=42, user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36, proxy-c/pre>
以上就介绍了nginx 设置匿名http正向代理,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。