Simple application of Nginx upstream module and proxy module

Source: Internet
Author: User

Nginx of Upstream modules and Proxy simple application of modules

nginx in web service is a powerful tool that can do static Span style= "FONT-FAMILY:CALIBRI;" >web service, of course its most common function is its load balancer, the following is just the application nginx upstream module and proxy module to do a little experiment. The function shown here is just the tip of the iceberg.

upstreem Use Note: 1 , use only http context. 2 server can only be used directly ip server IP The way to proxy the backend, the backend uses the apache web service.

experimental topology diagram:

650) this.width=650; "id=" Big_pic "alt=" wkiol1ucfvdzjowjaadlbadi5vw005.jpg "src=" http://home.51cto.com/ thumb.php?w=600&h=600&t=f&url=http://s3.51cto.com/wyfs02/m01/5b/36/ Wkiol1ucfvdzjowjaadlbadi5vw005.jpg "/>

Experiment Configuration

This experiment mainly uses nginx 's upstream module and proxy module.

Upstream Webservers {

Server 192.168.1.117 weight=1 max_fails=2 fail_timeout=3;

Server 192.168.1.119 weight=1 max_fails=2 fail_timeout=3;

Server 127.0.0.1:8080 backup;

}

server {

Listen 80; at this point the server listens on the tcp/80 Port.

server_name www.a.com ;

Location/{

root HTML;

Index index.html index.htm;

Proxy_pass http://webservers/;

Proxy_set_header X-real-ip $remote _addr;

}

}

server {

Listen 8080;

server_name 127.0.0.1;

Root/www/backup;

}

The above options are described below.

set_header x-real-ip $remote _addr; the proxy sends the header to the upstream server .

add_header X-via $server _addr// is the header that the agent sends to the client.

weight=#:// Weights

max_fails=#:// maximum number of failed attempts, default to 1 .

fail_timeout=time:// timeout for failed attempts, default to 301 .

Backup :                                           // when other services are hung up, it will automatically go to this page. However, no one node on-line backup will be online.

Experimental test

After the configuration is complete, you can test and add a test page to the two hosts on the back end. The httpd service is then started . IP access to nginx server :192.168.1.118

650) this.width=650; "alt=" wkiol1ucfu_ar7owaac5rnv8duq679.jpg "src=" http://home.51cto.com/thumb.php?w=600&h= 600&t=f&url=http://s3.51cto.com/wyfs02/m00/5b/36/wkiol1ucfu_ar7owaac5rnv8duq679.jpg "/>

Refresh Page

650) this.width=650; "alt=" wkiom1ucfc7tuwt7aadlu5ojo08446.jpg "src=" http://home.51cto.com/thumb.php?w=600&h= 600&t=f&url=http://s3.51cto.com/wyfs02/m00/5b/3c/wkiom1ucfc7tuwt7aadlu5ojo08446.jpg "/>

When the backend two servers are stopped at the same time, the service is refreshed again.

650) this.width=650; "alt=" wkiom1ucfc3r3fboaac4f_jfefo947.jpg "src=" http://home.51cto.com/thumb.php?w=600&h= 600&t=f&url=http://s3.51cto.com/wyfs02/m02/5b/3c/wkiom1ucfc3r3fboaac4f_jfefo947.jpg "/>

Nginx upstream module and proxy module simple application

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.