yum或者源码安装nginx,在nginx/conf/vhosts下新建配置文件test.conf(前提是在主配置文件中nginx.conf增加include hosts/*.conf)
upstream test {
ip_hash;
server 192.168.31.100(服务器1IP);
server 192.168.31.101(服务器2IP);
}
#IP后可支持权重,weight=2等
server {
listen 80;
server_name bbs.aaa.cn;#定义域名用于访问
location / {
proxy_pass http://test/; #为上面upstream 定义的别名
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}