: This article mainly introduces the Nginx Reverse proxy and server load balancer Deployment Guide. if you are interested in the PHP Tutorial, refer to it. 1. install
1) Download the Nginx installation package from the official Nginx website (http://nginx.org/en/download.html;
2) decompress the package and copy it to the deployment directory.
2. start and stop Nginx
Nginx currently only supports command line operations. before the operation, enter the doscommand environment and enter the Nginx deployment directory.
1) start Nginx: start nginx
2) stop Nginx: nginx-s stop
3) modify the configuration and restart: nginx-s reload
These three commands can be made into bat files and placed in the deployment directory for subsequent operations.
Start nginx. bat file content: start nginx
Stop nginx. bat file content: nginx-s stop
Reload nginx. bat file content: nginx-s reload
3. reverse proxy configuration
Modify the configuration of the nginx. conf file (such as nginx-1.5.13 \ conf \ nginx. conf) in the conf subdirectory under the deployment directory.
Reverse proxy configuration example:
Location /{
# Set the host header and client real address so that the server can obtain the real IP address of the client
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
# Disable Cache
Proxy_buffering off;
# Set the reverse proxy address
Proxy_pass http: // 192.168.1.1;
}
The proxy address is modified according to the actual situation.
4. server load balancer configuration
By default, nginx upstream implements load balancing in polling mode. In this mode, each request is distributed to different backend servers one by one in chronological order. if the backend server is down, it can be automatically removed.
Another method is ip_hash: each request is allocated according to the hash result of the access ip address. in this way, each visitor accesses a backend server and can solve the session problem.
Server load balancer configuration example:
Upstream backend {
# Ip_hash;
Server 192.168.1.htm;
Server 192.168.1.252;
Server 192.168.1.247;
}
Server {
Listen 80;
Server_name trffweb;
Location /{
# Reverse proxy address
Proxy_pass http: // backend;
}
}
The Upstream name and server address are modified according to the actual situation.
5. Complete 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.htm;
Server 192.168.1.252;
Server 192.168.1.247;
}
Server {
Listen 80;
Server_name 2;
Location /{
# Set the host header and client real address so that the server can obtain the real IP address of the client
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
# Disable Cache
Proxy_buffering off;
# Reverse proxy address
Proxy_pass http: // backend;
}
}
}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes the Nginx Reverse proxy and server load balancer Deployment Guide, including some content, hope to be helpful to friends who are interested in PHP tutorials.