Configure reverse proxy for Nginx

Source: Internet
Author: User
: This article describes how to configure reverse proxy for Nginx. For more information about PHP tutorials, see. 1, first create a configuration file,/etc/nginx/sites-enabled/reverse-proxy.conf

The content is as follows, and each line must end with a semicolon

Upstream monitor_server {# here is to use server load balancer so that multiple ip addresses can provide the same service. weight is the weight, server 10.10.12.203: 8080 weight = 2; server 10.12.202: 8080 weight = 4;} server {listen 8081; server_name www.xxx123.com; # reverse domain name proxy. different domain names direct to the same ip address, go through nginx, it also provides network services to different internal ip addresses. "www" does not omit location/{proxy_redirect off; proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ response; proxy_pass http: // monitor_server ;}} server {listen 8081; server_name localhost; location/{proxy_redirect off; proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; proxy_pass http: // 10.12.203: 8080 ;}}

2. include the preceding configuration file to nginx. conf.

Edit/etc/nginx. conf and add a sentence to http {}, for example

Include/etc/nginx/mime. types;
Default_type application/octet-stream;

Add the following sentence to the two rows:

Include/etc/nginx/sites-enabled/reverse-proxy.conf;

In this way, you can reference the reverse proxy configuration file, and then restart: service nginx restart

3. test

My test client is windows and the ip address is 10.10.12.73. The nginx server is in Ubuntu and the ip address is 10.10.2.176.

Open the c: \ windows \ System32 \ drivers \ etc \ hosts file, and add the following at the end:

10.10.2.176 www.xxx123.com

10.10.2.176 is the ip address of the nginx server. you can enter www.xxx123.com in the browser.

The above describes how to configure the reverse proxy for Nginx, including some content, and hope to help those who 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.