nginx做负载均衡配置
2015-12-25 10:48
501 查看
这里只写一下主要配置,至于其他的开启日志,设置权重之类的有兴趣的话可以自行脑补。
以下配置,监听本机的80端口,为www.baidu.com这个域名提供服务。
效果:来自www.baidu.com的请求,平均地转发到 192.16.0.1:80,
127.0.0.1:8080 两个服务上。(nginx.conf)
另外:淘宝tengine的配置和这个基本一样
upstream main {
server 192.16.0.1:80; //此处用于配置tomcat的路径,包括端口,此处也可以进行权重配置
server 127.0.0.1:8080;
}
server {
listen 80; //此处为监听端口,也就是访问时候URL的端口号
server_name www.baidu.com;
server_tokens off;
root /dev/null;
# Increase this if you want to upload larger attachmentsclient_max_body_size 20m;
# individual nginx logs for this vhostaccess_log /var/log/nginx/store_access.log;
error_log /var/log/nginx/store_error.log;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host teststore.boldseas.com;
#for proxy to IIS proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://main; //此处main和上边upstream main { .......
}中main的名字一样 ,需要注意
proxy_redirect off;
}
}
}
以下配置,监听本机的80端口,为www.baidu.com这个域名提供服务。
效果:来自www.baidu.com的请求,平均地转发到 192.16.0.1:80,
127.0.0.1:8080 两个服务上。(nginx.conf)
另外:淘宝tengine的配置和这个基本一样
upstream main {
server 192.16.0.1:80; //此处用于配置tomcat的路径,包括端口,此处也可以进行权重配置
server 127.0.0.1:8080;
}
server {
listen 80; //此处为监听端口,也就是访问时候URL的端口号
server_name www.baidu.com;
server_tokens off;
root /dev/null;
# Increase this if you want to upload larger attachmentsclient_max_body_size 20m;
# individual nginx logs for this vhostaccess_log /var/log/nginx/store_access.log;
error_log /var/log/nginx/store_error.log;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host teststore.boldseas.com;
#for proxy to IIS proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://main; //此处main和上边upstream main { .......
}中main的名字一样 ,需要注意
proxy_redirect off;
}
}
}
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- 负载均衡技术沙龙1期(关于咱的图片)
- 负载均衡沙龙活动第二期现场问答汇集
- Nginx 学习笔记(一)
- 流量引导:网络世界的负载均衡解密
- 流量引导:网络世界的负载均衡解密
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- 浅谈sqlserver的负载均衡问题
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略