Nginx Configuration forward Proxy support HTTPS

Source: Internet
Author: User
Tags curl port number

Nginx when the proxy, the site through the proxy access to HTTPS will fail, and the reason for the failure is that the client and the Nginx Proxy server to establish a connection failure, not nginx cannot forward the request for HTTPS. So the problem is how to establish a connection between the client and the Nginx proxy server. With this idea, it is easy to solve the problem. We can configure two server nodes, one to handle HTTP forwarding, the other to handle HTTPS forwarding, and the client to access the proxy over HTTP to differentiate between HTTP and HTTPS requests through the different ports of the access agent.

#HTTP
server{
Resolver 8.8.8.8;
Access_log/data/logs/nginx/access_proxy.log main;
Listen 80;
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass $scheme://$host $request_uri;
Proxy_set_header HOST $http _host;
Proxy_buffers 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;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}

#HTTPS
server{
Resolver 8.8.8.8;
Access_log/data/logs/nginx/access_proxy.log main;
Listen 443;
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass https://$host $request_uri;
Proxy_buffers 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;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}
If you visit an HTTP website, you can do this directly: Curl--proxy proxy_server:80 http://www.taobao.com/
If you visit an HTTPS Web site, such as https://www.alipay.com, you can use the Nginx HTTPS forwarding server:
Curl--proxy proxy_server:443 http://www.alipay.com

December 9, 2013 fill in notes:

Before Nginx configuration transparent proxy, there is no special for the configuration of the port, if the previous URL is http://www.test.com:8080/such address come over, through nginx forwarding actually to http://www.test.com : 80/above, in order to fix this problem, add the following configuration:  proxy_pass http://$host: $cookie _passport$request_uri;  which $cookie_ is to obtain information about the cookie in the request, the Passport's cookie value is the port number in the original URL. It can be seen that if you want to pass the Nginx forwarding, you need to first set a cookie, the value of this cookie named Passport,cookie is the port number in the original URL. If you use the Curl command to request a link, you can do this: curl-b passport=80--proxy proxy_server:80 http://www.taobao.com/where the-b parameter is to add a cookie  

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.