Nginx set anonymous HTTP forward proxy

Source: Internet
Author: User
Tags anonymous log log

Haven't written a blog for a long time, when I encountered difficulties, always find some of Daniel's articles on the internet to solve my problems. Before because of many things, are as a request, then there is time, I will try to write more blog, I encountered the problem of the solution, write to the blog, to share with you, as a feedback, but also hope that we have time to have their usual problems written blog, to share more people, so that everyone less detours.

These two days in the study of the Nginx agent, want to build an HTTP proxy server through Nginx, the website found this article (http://www.cnblogs.com/inteliot/archive/2013/01/11/2855907.html):

Configuring the Nginx HTTP proxy proxy, as with the [Squid] feature, applies to the forward proxy HTTP Web site. One, Nginx forward proxy profile:

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;
 
        Proxy_cache_valid 302 10m;
        Proxy_cache_valid 1h;
        Proxy_cache_valid any 1m;
#allow 127.0.0.1;
#deny all;
}
}


Second, Nginx forward agent configuration Description:

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, configure forward proxy parameters, are composed of Nginx variables. Where the Proxy_set_header part is configured to resolve if the URL contains a "." (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, reduce I/O, and proxy connection timeout.

Proxy_buffers 256 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 1h;
Proxy_cache_valid any 1m;
third, proxy HTTPS Web sites are not supported

Because Nginx does not support CONNECT, it cannot forward to the proxy Https website (online Banking, Gmail).
If you visit the Https Web site, for example: Https://www.google.com,Nginx access.log log is 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 are reported 404 (my Nginx version: 1.2), and then I found that need to change the Proxy_pass:

Proxy_pass $scheme://$host $request_uri;
Change into:

Proxy_pass $scheme://$http _host$request_uri;

This is OK, in addition I added the IP limit, you need to be able to open the above comments on the line:

Allow 127.0.0.1;
Deny all;

The above code is validated to be available. The server side of the code is as follows, but do not know how to bring a proxy-connection, this estimate can only be ordinary anonymous, not a senior anonymous:

Head info:{content-type=application/x-www-form-urlencoded charset=utf-8, Connection=close,  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-connection=keep-alive}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.