Vagrant
$ mkdir Frontend
$ cd Frontend
$ vagrant init ubuntu/trusty64
> Vagrantfile
config.vm.network "private_network", ip: "192.168.33.30"
$ vagrant up
$ vagrant ssh
#$ sudo passwd
Nginx
#$ sudo apt-get update
#$ sudo apt-get install nginx
> lookup address
#$ ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
Load Balancing
#$ cd /etc/nginx/sites-available/
#$ sudo vim default
> default
upstream backend.josaber.tw.com {
# 主机为两台虚拟机
server 192.168.33.20:8080;
server 192.168.33.21:8080;
# 保持通话由一个服务器处理
ip_hash;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
location / {
# 设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 禁用缓存
proxy_buffering off;
# 反向代理的地址
proxy_pass http://backend.josaber.tw.com;
}
}
References
Nginx实现负载均衡的几种方式
负载均衡----实现配置篇(Nginx)
Nginx负载均衡与高可用的实现
Nginx负载均衡
网友评论