nginx实现负载均衡
upstream backend {
server 192.168.1.108:80;
server 192.168.1.109:80;
}
location / {
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;
}
upstream django {
server 192.168.1.108:80;
server 192.168.1.109:80;
server 192.168.1.110:80;
server 192.168.1.111:80;
}
upstream php {
server 192.168.1.112:80;
server 192.168.1.113:80;
}
server {
listen 80;
server_name www.zhuangyan.cn;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
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://php;
}
}
server {
listen 80;
server_name app.zhuangyan.cn;
location / {
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://django;
}
location ~/static/ {
root /home/django/;
index index.html index.htm;
}
}
网友评论