Nginx provides Proxy service (website agent), Nginx to achieve load Balancing cluster and high-availability cluster, NGINX implementation of Web site static and dynamic page separation

Source: Internet
Author: User
Tags nginx server

Static pages: pages written in static programming language are static pages, support static pages of the language, CSS HTML XML, do not manually change the source code, the page will not change.

Dynamic pages: Pages written in dynamic programming languages are dynamic pages, the languages that support dynamic pages are, Java PHP. NET, which displays different pages depending on the time users visit and the different users.


Nginx website Service Agent

Experiment (i) experimental purpose: Nginx to implement reverse proxy instead of public network users to access the private network of the web page .

Lab Environment:

Intranet Web server: IP address: 192.168.1.1 Host Name: FANLJ

Nginx Proxy Server: IP address: 192.168.1.254 and 1.1.1.254 host name: localhost

Public network User: IP address: 1.1.1.1 host Name: Fanxiaohui

Experiment Preparation:

Configure intranet Web page with Apache service default page content is 192.168.1.1

1. On the intranet Web server, install the package on the IP address on 192.168.1.1 to start the service and local tests.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CF/wKiom1Xtf1qSdj_jAAEBDyZLdXM385.jpg "title=" Qq20150907201525.png "alt=" Wkiom1xtf1qsdj_jaaebdyzldxm385.jpg "/>

2. Modify the Master profile to provide proxy services

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CC/wKioL1XtlAPSloznAAEOFktr43s956.jpg "title=" Qq20150907213423.png "alt=" Wkiol1xtlapsloznaaeofktr43s956.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/D0/wKiom1XtkjXzlScFAAFufCmxLf4966.jpg "title=" Qq20150907213553.png "alt=" Wkiom1xtkjxzlscfaafufcmxlf4966.jpg "/>

3. When the client IP address is tested for 1.1.1.1, the page displayed when the user accesses 1.1.1.254 is 192.168.1.1 page content is 192.168.1.1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CC/wKioL1Xtlg6QYMSlAACxNcoh6hU471.jpg "title=" Qq20150907214229.png "alt=" Wkiol1xtlg6qymslaacxncoh6hu471.jpg "/>

4. When the intranet Web server has more than one site server configuration, upstream defines the server group

Lab Environment:

Intranet Web server: IP address: 192.168.1.1 Host Name: FANLJ

Intranet Web server: IP address: 192.168.1.2 host Name: Fanxiaohui

Nginx Proxy Server: IP address: 192.168.1.254 and 1.1.1.254 host name: localhost

Test in Nginx native test

Experiment Preparation:

Configure IP address for 192.168.1.1 Intranet Web page with Apache service The default page content is 192.168.1.1, Configure IP address for 192.168.1.2 intranet Web page with Apache service the default Web page content is 192.168.1.2.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CD/wKioL1XtmN3zp7b8AAE0XMR1dD4041.jpg "title=" Qq20150907215414.png "alt=" Wkiol1xtmn3zp7b8aae0xmr1dd4041.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CD/wKioL1XtmPrQL9h3AAD2Fq8-1IA643.jpg "title=" Qq20150907215533.png "alt=" Wkiol1xtmprql9h3aad2fq8-1ia643.jpg "/>

1. Modify the Nginx master configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CD/wKioL1XtmeziUpNaAAFGNr8hSCE179.jpg "title=" Qq20150907215930.png "alt=" Wkiol1xtmeziupnaaafgnr8hsce179.jpg "/>

2. Restart the service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/D0/wKiom1XtmHLxFrvvAAF6RSNV7TE415.jpg "title=" Qq20150907220233.png "alt=" Wkiom1xtmhlxfrvvaaf6rsnv7te415.jpg "/>

3. Testing on the client

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/D0/wKiom1XtmRCgtIzVAADffhtCQkU512.jpg "title=" Qq20150907220448.png "alt=" Wkiom1xtmrcgtizvaadffhtcqku512.jpg "/>

Summary: Load Balancing when Nginx provides multiple site services.

Experiment (II)

Experimental purpose: According to the server configuration and performance of different nginx can be set according to the actual situation

Set the Nginx distribution policy
Polling (default) each request is assigned to a different back-end server in chronological order the weight value is 1
If the back-up server is down, it will automatically reject
Weight=1 Load Balancing cluster

1. Modify the master configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/D0/wKiom1XtmpiATzoSAAFGNr8hSCE033.jpg "title=" Qq20150907215930.png "alt=" Wkiom1xtmpiatzosaafgnr8hsce033.jpg "/>

2. Client-side testing

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/D0/wKiom1XtmnrCTiaVAADffhtCQkU329.jpg "title=" Qq20150907220448.png "alt=" Wkiom1xtmnrctiavaadffhtcqku329.jpg "/>

Weight Specifies that the polling chance weight and the access ratio are proportional to the performance of the backend server, the default value is 1.

Experimental environment: Depending on the configuration and performance of the server, the user accesses the server and expects the Web page provided on the 192.168.1.1 to appear 3 times, accessing the 192.168.1.2 page 2 times.

1. Modify the master configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/D1/wKiom1XtnCOgtmkhAAEm3YYal4M741.jpg "title=" Qq20150907221719.png "alt=" Wkiom1xtncogtmkhaaem3yyal4m741.jpg "/>

2. Restart the service

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CD/wKioL1Xtnl_BiKMKAACz6Bc2qkg770.jpg "title=" Qq20150907221814.png "alt=" Wkiol1xtnl_bikmkaacz6bc2qkg770.jpg "/>

3. Testing

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CD/wKioL1XtnovQYQNGAAD7b9EkuZQ255.jpg "title=" Qq20150907221916.png "alt=" Wkiol1xtnovqyqngaad7b9ekuzq255.jpg "/>


Ip_hash each request is allocated according to the hash result of the access IP
This allows each visitor to have fixed access to a back-end server, which can solve the session problem
1. Modify the master configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/D1/wKiom1XtnTCjVm7LAAE1P8GwalE925.jpg "title=" Qq20150907222243.png "alt=" Wkiom1xtntcjvm7laae1p8gwale925.jpg "/>

2. Restart the service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/D1/wKiom1XtnZDSSTmMAADYoiDO-yM055.jpg "title=" Qq20150907222421.png "alt=" Wkiom1xtnzdsstmmaadyoido-ym055.jpg "/>

3. Test on the client.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CE/wKioL1Xtn-vC3MNOAACbSq_AWA4178.jpg "title=" Qq20150907222510.png "alt=" Wkiol1xtn-vc3mnoaacbsq_awa4178.jpg "/>

Fair by the response time of the backend server to allocate a short priority assignment for request response time, this algorithm is not supported by default.

Experiment (III)

Experiment Objective: To realize the High availability cluster configuration of Nginx server

Provides a highly available cluster by setting the state of the server group service.

Down: Indicates that the current server is temporarily not participating in the load

The administrator temporarily does not want to let the Web site on 192.168.1.1 serve.

1. Modify the master configuration file

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CE/wKioL1Xto4KSR_8aAADtT560tes691.jpg "title=" Qq20150907224029.png "alt=" Wkiol1xto4ksr_8aaadtt560tes691.jpg "/>

2. Restart the service

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CE/wKioL1Xto8SDrKGeAADkaVToDFs034.jpg "title=" Qq20150907224136.png "alt=" Wkiol1xto8sdrkgeaadkavtodfs034.jpg "/>

3. Testing

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/D1/wKiom1XtocqS6JD2AACEr0Y6430076.jpg "title=" Qq20150907224223.png "alt=" Wkiom1xtocqs6jd2aacer0y6430076.jpg "/>


Max_fails: The number of times the request failed to be allowed (default is 1), which returns the error defined by the Proxy_next_upstream module when this number is exceeded
Fail_timeout:max_fails time to suspend service after a failure
Server 192.168.1.1:80 max_fails=3 fail_timeout=30s;

When the user accesses the server 192.168.1.1, if the connection 3 times the request fails, then the service is temporarily unavailable within 30s.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CE/wKioL1XtpXfCvU5BAAEoSydZbq4264.jpg "title=" Qq20150907224847.png "alt=" Wkiol1xtpxfcvu5baaeosydzbq4264.jpg "/>

Backup: When all other non-backup machines are down or busy, the request is sent to the backup machine for a highly available cluster.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CE/wKioL1XtpfmiXNiFAAE2Ruy4O2w502.jpg "title=" Qq20150907225101.png "alt=" Wkiol1xtpfmixnifaae2ruy4o2w502.jpg "/>


Experiment (IV)

Experimental Purpose: Nginx provides Web site static and dynamic page separation.

Lab Environment:

Intranet Web server: IP address: 192.168.1.1 hostname: FANLJ storing static pages

Intranet Web server: IP address: 192.168.1.2 host Name: Fanxiaohui store Dynamic page

Nginx Proxy Server: IP address: 192.168.1.254 and 1.1.1.254 host name: localhost

static pages (CSS HTML XML) are stored in 192.168.1.1 *.html

Dynamic pages (PHP java. net) are stored in 192.168.1.2 *.php

When a user accesses http://nginx-server/test.html access to a page on 192.168.1.1

When a user accesses http://nginx-server/test.php access to a page on 192.168.1.2

Environment Preparation:

Programming a PHP-enabled file on 192.168.1.2 for test.php,

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CF/wKioL1XtvFWRdSIZAABTmJ9jEwc934.jpg "title=" Qq20150908002623.png "alt=" Wkiol1xtvfwrdsizaabtmj9jewc934.jpg "/>

Test locally, if there is no display, indicates that the support PHP package is not installed, installs all PHP packages, and then restarts the HTTPD service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/D2/wKiom1XtuoSTdkXBAAAnMxqibwo778.jpg "title=" Qq20150908002754.png "alt=" Wkiom1xtuostdkxbaaanmxqibwo778.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CF/wKioL1XtvOjA8rh5AAAoytBQIWg809.jpg "title=" Qq20150908002850.png "alt=" Wkiol1xtvoja8rh5aaaoytbqiwg809.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/D2/wKiom1XtutezGiCkAAA-JLVG61U012.jpg "title=" Qq20150908002918.png "alt=" Wkiom1xtutezgickaaa-jlvg61u012.jpg "/>

Write a file on 192.168.1.1 for test.html, test locally

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/CF/wKioL1XtvaCAiL6lAACoflN81dY461.jpg "title=" Qq20150908003156.png "alt=" Wkiol1xtvacail6laacofln81dy461.jpg "/>

1. Modify the Nginx master profile to remove lines and blank lines that begin with # in the main configuration file.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CF/wKioL1XtwCPjEXCXAABnyoChrG4296.jpg "title=" Qq20150908004237.png "alt=" Wkiol1xtwcpjexcxaabnyochrg4296.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/D3/wKiom1XtwkiAOfxKAAFnQjwRvMQ278.jpg "title=" Qq20150908010058.png "alt=" Wkiom1xtwkiaofxkaafnqjwrvmq278.jpg "/>

2. Check the Nginx Master profile syntax for errors and restart the service.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/CF/wKioL1XtwleAS0OaAADU5IHD3Kg028.jpg "title=" Qq20150908005131.png "alt=" Wkiol1xtwleas0oaaadu5ihd3kg028.jpg "/>

3. Test in Nginx native

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/CF/wKioL1XtxLbxUGZMAACNaG_EqCI160.jpg "title=" Qq20150908010208.png "alt=" Wkiol1xtxlbxugzmaacnag_eqci160.jpg "/>



This article is from the "Down to earth" blog, make sure to keep this source http://343614597.blog.51cto.com/7056394/1692579

Nginx provides Proxy service (website agent), Nginx to achieve load Balancing cluster and high-availability cluster, NGINX implementation of Web site static and dynamic page separation

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.