Nginx reverse proxy, load balancer

Source: Internet
Author: User
Tags nginx reverse proxy

in order to implement nginx "reverse proxy and load balancing function, we need to use httpproxymodule and httpupstreammodule module. where httpproxymodule The function of the module is to forward the user's data request to another server, httpupstreammodule ip nginx The default auto-compile module.

When acting on a single host, thenginx configuration file is:

server {

Listen 80;

server_name aaa.com;

Location/{

Proxy_pass/HTTP 10.10.10.128 /;

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

}

# Access_log/home/logs/aaa_access.log combined;

}

if the back-end machine has more than one (load Balancing)

N The ginx configuration file is written

Upstream BBB

{

Server 192 : 168.182.129 ;

Server 192 : 168.182.131 ;

}

server {

Listen 80;

server_name bbb.com;

Location /{

Proxy_pass http://bbb/;

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

}

# Access_log/home/logs/bb_access.log combined;

}

Proxy all domain names on a server

First in the vhosts directory need to build two files, one is the servername list file, one is a virtual host configuration file

The contents of two files were

(1) servername

server_name aaa.com 111.com // in this simple line, of course, this server_name can continue to add

(2) virtual Host configuration file

server {

Listen 80;

Include Vhosts/servername; The file here is the top servername list file .

Location/{

Proxy_pass/HTTP 10.10.10.128  /; This is the server IP address that needs to be the proxy .

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

}

Access_log/dev/null;

}


Nginx reverse proxy, load balancer

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.