添加源地址:
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装nginx:
yum install -y nginx
启动nginx:
systemctl start nginx
一般默认是80端口,可以在这里修改vi /etc/nginx/conf.d/default.conf
修改配置进行负载均衡:
1,打开配置文件:vi /etc/nginx/nginx.conf
在文件加入你要负载的ip:
upstream upstream_name{
server 10.201.61.218:8080;
server 10.201.62.39:8080;
}
2,在上图的文件中可以看到有文件是包含进来的 include /etc/nginx/conf.d/*.conf;
在/etc/nginx/conf.d目录下只有default.conf文件并打开:
vi /etc/nginx/conf.d/default.conf
把原来的location / {......}的内容修改,并且注意upstream_name是对应你的nginx.conf的upstream_name:
location / {
proxy_pass http://upstream_name;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
重启:
systemctl restart nginx
完毕!