Nginx簡單的負載均衡配置示例
01
user www www;
02
03
worker_processes 10;
04
05
#error_log logs/error.log;
06
#error_log logs/error.log notice;
07
#error_log logs/error.log info;
08
09
#pid logs/nginx.pid;
10
11
#最大文件描述符
12
worker_rlimit_nofile 51200;
13
14
events
15
{
16
use epoll;
17
18
worker_connections 51200;
19
}
20
21
http
22
{
23
include conf/mime.types;
24
default_type application/octet-stream;
25
26
keepalive_timeout 120;
27
28
tcp_nodelay on;
29
30
upstream www.s135.com {
31
server 192.168.1.2:80;
32
server 192.168.1.3:80;
33
server 192.168.1.4:80;
34
server 192.168.1.5:80;
35
}
36
37
upstream blog.s135.com {
38
server 192.168.1.7:8080;
39
server 192.168.1.7:8081;
40
server 192.168.1.7:8082;
41
}
42
43
server
44
{
45
listen 80;
46
server_name www.s135.com;
47
48
location / {
49
proxy_pass http://www.s135.com;
50
proxy_set_header Host $host;
51
proxy_set_header X-Real-IP $remote_addr;
52
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
53
}
54
55
log_format www_s135_com '$remote_addr - $remote_user [$time_local] $request '
56
'"$status" $body_bytes_sent "$http_referer" '
57
'"$http_user_agent" "$http_x_forwarded_for"';
58
access_log /data1/logs/www.log www_s135_com;
59
}
60
61
server
62
{
63
listen 80;
64
server_name blog.s135.com;
65
66
location / {
67
proxy_pass http://blog.s135.com;
68
proxy_set_header Host $host;
69
proxy_set_header X-Real-IP $remote_addr;
70
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71
}
72
73
log_format blog_s135_com '$remote_addr - $remote_user [$time_local] $request '
74
'"$status" $body_bytes_sent "$http_referer" '
75
'"$http_user_agent" "$http_x_forwarded_for"';
76
access_log /data1/logs/blog.log blog_s135_com;
77
}
78
}