nginx负载均衡配置

  1. #user  nobody;  
  2. worker_processes  1;  
  3.   
  4. error_log  logs/error.log;  
  5.   
  6. events {  
  7.     worker_connections  1024;  
  8. }  
  9.   
  10.   
  11. http {  
  12.     include       mime.types;  
  13.     default_type  application/octet-stream;  
  14.   
  15.     sendfile        on;  
  16.     keepalive_timeout  65;  
  17.   
  18.     #gzip  on;  
  19.     upstream  www.docyeah.com   {  
  20.               server   192.168.1.11:8080;  
  21.               server   192.168.1.101:8080;  
  22.     }  
  23.     server {  
  24.         listen       80;  
  25.         server_name  www.docyeah.com;  
  26.         charset utf-8;  
  27.         location / {  
  28.             root   html;  
  29.             index  index.html index.htm;  
  30.             proxy_pass        http://www.docyeah.com;  
  31.             proxy_set_header  X-Real-IP  $remote_addr;  
  32.             client_max_body_size  100m;  
  33.         }  
  34.   
  35.   
  36.         location ~ ^/(WEB-INF)/ {   
  37.         deny all;   
  38.         }   
  39.   
  40.         error_page   500 502 503 504  /50x.html;  
  41.         location = /50x.html {  
  42.             root   html;  
  43.         }  
  44.   
  45.     }  

  1. 将www.docyeah.com替换成你的域名

    192.168.1.11和192.168.1.101替换成你服务器的IP

     

    OK,已经完成。启动nginx即可。

    nginx在配置upstream时,有两个参数: 
    ip_hash(同一IP一直使用同一台server服务) 
    weight(server的使用权重,数值越大,nginx分发的请求越多) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值