首页 > 后端开发 > php教程 > nginx做负载均衡配置

nginx做负载均衡配置

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-07-29 09:09:11
原创
1050 人浏览过

这里只写一下主要配置,至于其他的开启日志,设置权重之类的有兴趣的话可以自行脑补。  

以下配置,监听本机的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做负载均衡配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板