Nginx Configure reverse Proxy

Source: Internet
Author: User
Tags nginx server


1, first create a new configuration file,/etc/nginx/sites-enabled/reverse-proxy.conf

nginx reverse proxy


The contents are as follows, nginx proxy manager each line requires a semicolon ending


nginx proxy_pass



Upstream Monitor_server  #这里是为了使用负载均衡, so that multiple IP can provide the same service, weight for the right value,
    server 10.10.12.203:8080 weight=2;  # The higher  the weight value, the greater the probability of being selected
    server 10.10.12.202:8080 weight=4;

Server 
{
    listen 8081;
    server_name www.xxx123.com; # Reverse Domain name agent, different domain name is to point to the same access IP, after Nginx, and to different internal IP to provide network services, "www" Do 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 $proxy _add_x_forwarded_for;
        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.10.12.203:8080
    }
}

2, the above configuration file include to nginx.conf





Edit/etc/nginx/nginx.conf, add a word in http{}, such as



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



Add a sentence below two lines:jwilder nginx proxy



include/etc/nginx/sites-enabled/reverse-proxy.conf;nginx reverse proxy example



In this way, you can refer to the reverse proxy configuration file, nginx reverse proxy docker and then restart it: Service nginx restart






3, test



My test client is Windows,ip 10.10.12.73 While the Nginx server is in Ubuntu and IP 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



Where 10.10.2.176 for the Nginx server IP, the results can be entered in the browser www.xxx123.com, you can see it was forwarded.





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.