Nginx sets anonymous http forward proxy

Source: Internet
Author: User
: This article describes how to set up an anonymous http forward proxy for nginx. For more information about PHP tutorials, see. I haven't written a blog for a long time. when I encounter difficulties, I can always find some articles written by the experts on the Internet to solve my problems. In the past, because there were a lot of things, I used to be a solver. I will try to write as many blogs as possible next, write the solutions to my problems to my blog, and share them with you for feedback, I also hope that you will be able to write your usual problems into a blog and share them with more people, so that you can avoid detours.

These two days in the study of nginx forward proxy, 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 ):

Configure the Nginx Http Proxy server, which has the same function as [Squid] and is applicable to forward Proxy Http websites.

1. 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 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;
    }}
2. Nginx forward proxy configuration instructions:

1. configure the DNS resolution IP address, such as Google Public DNS, and the timeout time (5 seconds ).

resolver 8.8.8.8;resolver_timeout 5s;
2. configure forward proxy parameters, which are composed of Nginx variables. The proxy_set_header configuration is used to solve the Nginx 503 error after the URL contains "." (dot.

proxy_pass $scheme://$host$request_uri;proxy_set_header Host $http_host;
3. configure the cache size, disable disk cache read/write, and reduce I/O, as well as the proxy connection timeout.

proxy_buffers 256 4k;proxy_max_temp_file_size 0;proxy_connect_timeout 30;
4. configure the Http status cache time of the proxy server.

proxy_cache_valid 200 302 10m;proxy_cache_valid 301 1h;proxy_cache_valid any 1m;
3. proxy Https websites not supported

Because Nginx does not support CONNECT, it cannot forward proxy Https websites (online banking, Gmail ).
If you access an Https website such as a https://www.google.com, the Nginx access. log is as follows:

"CONNECT www.google.com:443 HTTP/1.1" 400

The author wrote a great job. However, I encountered a problem during the configuration process, that is, when I accessed the page through the configured proxy, 404 was reported (my nginx version: 1.2 ), later I found that I needed to change proxy_pass:

proxy_pass $scheme://$host$request_uri;
Changed:
proxy_pass $scheme://$http_host$request_uri;

In this way, I add ip restrictions. you can open the above annotations as needed:

allow 127.0.0.1;deny all;

It has been verified that the above code can be used. The code obtained by the server is as follows, but I don't know how to bring a proxy-connection. this is probably only common anonymity, not advanced 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 preceding section describes how to set up an anonymous http forward proxy for nginx, including the following content. if you are interested in the PHP Tutorial.

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.