基於node和nignx和mongo搭建負載均衡
nginx配置:
upstream back { #使用upstream設定不同的權重模組,權重越高nginx傳遞越多的連線,back是自定義的一個名稱.會連結到proxy_pass http://back;
server 10.0.0.5:10000 fail_timeout=15s;
server 10.0.0.7:10000 fail_timeout=15s;
ip_hash; #採用ip雜湊的演算法,設定負載均衡
}
server {
client_max_body_size 50m;
server_name load.enterplorer.com;
access_log /var/log/nginx/back.access.log;
error_log /var/log/nginx/back.error.log;
listen 80;
location / {
proxy_pass http://back; # 反向代理到上游伺服器地址,就是upstream back 的back
proxy_http_version 1.1; #這是http請求設定的
proxy_set_header Connection ""; #負載均衡的頭部保持連線,不返回close
proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
}
}
mongodb配置:
dbpath=/home/mongodb/data
logpath=/home/mongodb/log/mongodb.log
logappend=true
port=27017
fork=true
noauth=true
master=true
oplogSize=2048
slave=true
source=10.0.0.7
slavedelay=1
autoresync=true