Long time no blog, in my difficult times, can always find some articles from the online Daniel wrote, solve my problem. Before because of things, are as a request, and then there is time, I will try to write more blog, I encountered the solution of the problem, write to the blog, share to everyone, as feedback, but also hope that we have time to write their usual problems as a blog, to share more people, so that people less detours.
These two days in research Nginx forward agent, want to build an HTTP proxy server through Nginx, Web site found this article (http://www.cnblogs.com/inteliot/archive/2013/01/11/2855907.html):
Configure the Nginx Http proxy proxy Server, like the [Squid] function, for The forward Proxy Http Web site.
One, Nginx forward proxy configuration file:
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 4k; Proxy_max_temp_file_size 0; Proxy_connect_timeout; Proxy_cache_valid 302 10m; Proxy_cache_valid 301 1h; Proxy_cache_valid any 1m;
#allow 127.0.0.1; #deny all;
}}
Two, Nginx forward proxy configuration instructions:
1, configure DNS resolution IP address, such as Google public DNS, and timeout time (5 seconds).
Resolver 8.8.8.8;resolver_timeout 5s;
2, the configuration of the forward proxy parameters, are composed of Nginx variables. Where the Proxy_set_header section is configured to resolve if the URL is in "." (dot) after Nginx 503 error.
Proxy_pass $scheme://$host $request_uri;proxy_set_header host $http _host;
3, configure cache size, turn off disk cache read and write reduced I/O, and proxy connection time-out.
Proxy_buffers 4k;proxy_max_temp_file_size 0;proxy_connect_timeout 30;
4, configure the proxy server Http state cache time.
Proxy_cache_valid 302 10m;proxy_cache_valid 301 1h;proxy_cache_valid any 1m;
third, Proxy Https Web site is not supported
Because Nginx does not support CONNECT, Unable to forward proxy Https website (online Banking, Gmail).
If you visit an HTTPS website, such as: Https://www.google.com,Nginx Access.log log as follows:
"CONNECT www.google.com:443 http/1.1" 400
The author is very good, however, I encountered a problem in the configuration process, that is, through the configuration of the proxy access page is reported 404 (my Nginx version: 1.2), then I found the need to change the Proxy_pass:
Proxy_pass $scheme://$host $request_uri;
Change to:
Proxy_pass $scheme://$http _host$request_uri;
This is OK, plus I added the IP restrictions, you need to be able to open the above comments on the line:
Allow 127.0.0.1;deny all;
It is verified that the above code is available. Server-side get the code below, but do not know how to bring a proxy-connection, this estimate can only be ordinary anonymous, not considered high-level anonymity:
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>
The above describes the Nginx set anonymous HTTP forward proxy, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.