您的位置:首页 > 运维架构 > Nginx

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;   

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx 负载均衡