LNMP-Nginx负载均衡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP-Nginx负载均衡相关的知识,希望对你有一定的参考价值。
1、获取网站IP地址
[[email protected] ~]# yum install -y bind-utils ##安装dig命令 [[email protected] ~]# dig baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-50.el7_3.1 <<>> baidu.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63640 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;baidu.com. IN A ;; ANSWER SECTION: baidu.com. 37 IN A 123.125.114.144 ##地址1 baidu.com. 37 IN A 220.181.57.217 ##地址2 baidu.com. 37 IN A 111.13.101.208 ##地址3 ;; Query time: 8 msec ;; SERVER: 114.114.114.114#53(114.114.114.114) ;; WHEN: Tue Aug 15 21:55:50 CST 2017 ;; MSG SIZE rcvd: 86
2、编辑配置文件
[[email protected] ~]# vi /usr/local/nginx/conf/vhost/ld.conf upstream baidu { ip_hash; ##算法 server 123.125.114.144:80; server 220.181.57.217:80; server 111.13.101.208:80; } server { listen 80; server_name www.baidu.com; ##域名 location / { proxy_pass http://baidu; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
3、检查与重载
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload
4、测试效果
[[email protected] ~]# curl -x127.0.0.1:80 www.baidu.com <html> <meta http-equiv="refresh" content="0;url=http://www.baidu.com/"> </html>
本文出自 “Gorilla City” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1956575
以上是关于LNMP-Nginx负载均衡的主要内容,如果未能解决你的问题,请参考以下文章