nginx 负载均衡的配置方法
在 site-avaliable
新建一个配置项
两个服务器:
- 128.199.185.23:3000 (express)
- 128.199.86.27 (nginx)
express.conf
:
upstream express {
server 128.199.185.23:3000;
#server 128.199.185.24:3000
}
server {
listen 3000;
proxy_set_header Host $host;
proxy_http_version 1.1;
location / {
proxy_pass http://express;
}
}
当其中一个服务不可用的时候,切换到下一个服务:
proxy_next_upstream error timeout invalid_header http_500;
proxy_connect_timeout 2;
完整配置:
upstream express {
server 128.199.185.23:3000;
server 128.199.185.24:3000;
}
server {
listen 3000;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_next_upstream error timeout invalid_header http_500;
proxy_connect_timeout 2;
location / {
proxy_pass http://express;
}
}
评论列表 (0条):
加载更多评论 Loading...