Nginx simple load balancing configuration example

  • 2020-05-06 12:12:09
  • OfStack

The user accesses http:// www.net.com.cn and loads it to four servers: 192.168.1.2:80, 192.168.1.3:80, 192.168.1.4:80, and 192.168.1.5:80.
The user accesses // www.jb51.net and loads it to ports 8080, 8081, and 8082 of the 192.168.1.7 server.
The following is the configuration file nginx.conf:
Reference
[table = 95%] [tr] [td] user www www;
worker_processes 10;
# error_log logs/error. log;
# error_log logs/error log notice;
# error_log logs/error log info;
# pid logs/nginx. pid;
Maximum file descriptor
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime. types;
default_type application/octet - stream;
keepalive_timeout 120;
tcp_nodelay on;
upstream www. net - hb. com. cn {
server 192.168.1.2 instead: 80;
server 192.168.1.3:80;
server 192.168.1.4:80;
server 192.168.1.5:80;
}
upstream blog. s135. com {
server 192.168.1.7:8080;
server 192.168.1.7:8081;
server 192.168.1.7:8082;
}
server
{
listen 80;
server_name www. net - hb. com. cn;
location / {
proxy_pass http: / / www net - hb. com. cn;
proxy_set_header Host $host;
proxy_set_header X Real - IP $remote_addr;
proxy_set_header X Forwarded - For $proxy_add_x_forwarded_for;
}
Es166en_www_s135_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'" $http_user_agent "" $http_x_forwarded_for";
access_log data1 / logs/www log www_s135_com;
}
server
{
listen 80;
server_name blog. s135. com;
location / {
proxy_pass / / www jb51. net;
proxy_set_header Host $host;
proxy_set_header X Real - IP $remote_addr;
proxy_set_header X Forwarded - For $proxy_add_x_forwarded_for;
}
log_format s_es255_com '$remote_addr '- $remote_user [$time_local] $request'
'"$status" $body_bytes_sent "$http_referer" '
'" $http_user_agent "" $http_x_forwarded_for";
access_log data1 / logs/blog log blog_s135_com;
}
}[/td][/tr][/table] attachment: the installation method of Nginx can refer to the following paragraph of the article "Nginx 0.5.31 + PHP 5.2.4(FastCGI), which can support more than 30,000 concurrent connections, which is more than 10 times the Web server" (for load balancing only, there is no need to support the installation method of PHP) :
Ii. Install PHP 5.2.4(FastCGI mode)
4. Create www users and groups, and the directory they use:
3. Install Nginx 0.5.31
1. pcre library required to install Nginx:
2. Install Nginx
3. Create Nginx log directory
5. Start Nginx

Related articles: