Linux system configuration of nginx load balancing
- 2020-05-30 21:44:14
- OfStack
Details of Linux system configuration of nginx load balancing
Several ways of load balancing:
1. Polling: by default, all servers will be accessed one by one in chronological order. If any server goes down, it will be deleted automatically.
2.weight: the bearing probability of the server is proportional to weight, which can be configured when the server is not evenly configured;
3.ip_hash: calculate hash for ip of each request, and assign the corresponding server according to the rules set in 1 (session sharing can be solved);
4.fair: requests are allocated according to the response time of each server (rt). rt knows the priority allocation;
5.url_hash: requests are allocated according to the hash value of access to url;
NGINX profile:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include blockip.conf; # screening IP
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream www. The domain name .com {
server IP1: port ; # The server 1
server IP2: port ; # The server 2
ip_hash; # Rules for load balancing
}
server {
listen 80 default_server; #NGINX The service domain name to point to
listen [::]:80 default_server;
server_name IP; #NGINX Pointed server IP
root /usr/share/nginx/html; #NGINX HTML directory
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://www. The domain name .com; #nginx Pointed domain name
}
error_page 404 /404.html;
location = /40x.html { #404 page
}
error_page 500 502 503 504 /500.html;
location = /500.html { #500 page
}
}
}
Thank you for reading, I hope to help you, thank you for your support of this site!