有两台服务器,xx.xx.xx.01 和 xx.xx.xx.02,01 作为主服务器,在 01 上做负载均衡,配置如下 但是每次请求都会被转发到 02 这台服务器,即使
upstream balance {
server xx.xx.xx.01:80;
server xx.xx.xx.02:80;
}
xx.xx.xx.01 的配置
http {
passenger_root /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.11;
passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream balance {
server xx.xx.xx.02:80;
}
server {
listen 80;
server_name www.xx.com;
location / {
proxy_pass http://balance;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
root /home/my_project/public;
passenger_enabled on;
}
}
xx.xx.xx.02 的配置
http {
passenger_root /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.11;
passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.xx.com;
root /home/my_project/public;
passenger_enabled on;
}
}