Nginx reverse proxy and Load Balancer Deployment Guide

Source: Internet
Author: User
Tags nginx reverse proxy
1. Installation

1) Download the latest version of Nginx (currently version 1.9.2) from the Nginx official website download page (http://nginx.org/en/download.html) to install the package;

2) Copy to the deployment directory after decompression.

2. Start and stop Nginx

Nginx currently only supports command line operations, before operation into the DOS command environment, and into the Nginx deployment directory.

1) Start Nginx:start nginx

2) Stop the Nginx:nginx-s stop

3) Reboot after configuration modification: Nginx-s Reload

These three commands can be made into bat files, placed in the deployment directory for easy follow-up operation.

Start Nginx.bat file contents: Start Nginx

Stop Nginx.bat file contents: Nginx-s stop

Reload Nginx.bat file contents: Nginx-s Reload

3. Reverse proxy configuration

Modify the contents of the nginx.conf file (such as nginx-1.5.13\conf\nginx.conf) in the Conf subdirectory under the deployment directory to adjust the relevant configuration.

Example of a reverse proxy configuration:

Location/{

#设置主机头和客户端真实地址 so that the server obtains the client's real IP

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_buffering off;

#设置反向代理的地址

Proxy_pass http://192.168.1.1;

}

The proxy address is modified according to the actual situation.

4. Load Balancing Configuration

Nginx upstream by default is a poll-based load balancing, in this way, each request in chronological order to a different back-end server, if the backend server down, can be automatically rejected.

Another way is Ip_hash: Each request is allocated according to the hash result of the access IP, so that each visitor fixed access to a back-end server can solve the session problem.

Example of a load balancer configuration:

Upstream Backend {

#ip_hash;

Server 192.168.1.251;

Server 192.168.1.252;

Server 192.168.1.247;

}

server {

Listen 80;

server_name trffweb;

Location/{

#反向代理的地址

Proxy_pass Http://backend;

}

}

Upstream naming and server addresses are modified according to the actual situation.

5. Full Configuration Example

Nginx.conf:

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

Upstream Backend {

#ip_hash;

Server 192.168.1.251;

Server 192.168.1.252;

Server 192.168.1.247;

}

server {

Listen 80;

server_name 2;

Location/{

#设置主机头和客户端真实地址 so that the server obtains the client's real IP

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_buffering off;

#反向代理的地址

Proxy_pass Http://backend;

}

}

}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the Nginx reverse proxy and Load Balancer Deployment Guide, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.