LNMP架构负载均衡及HTTPS相关配置

作者 : 开心源码 本文共2261个字,预计阅读时间需要6分钟 发布时间: 2022-05-12 共137人阅读

Nginx负载均衡

负载均衡原理上就是代理商,只不过通过设置多个代理商服务器来实现多客户访问时的负载均衡。同时也可以在某个代理商服务器无法访问时,切换到另外的代理商服务器,从而实现访问不间断的目的。

下面以qq.com为例,配置负载均衡

  1. 先通过dig命令查看域名及其ip
# dig命令由bind-utils包安装
[root@localhost ~]# yum install -y bind-utils
[root@localhost ~]# dig qq.com
; <> DiG 9.9.4-RedHat-9.9.4-51.el7_4.1 <> qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65328
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;qq.com.INA
;; ANSWER SECTION:
qq.com.404INA61.135.157.156
qq.com.404INA125.39.240.113
;; Query time: 40 msec
;; SERVER: 119.29.29.29#53(119.29.29.29)
;; WHEN: 四 1月 04 22:02:25 CST 2018
;; MSG SIZE rcvd: 67
  1. 配置虚拟主机配置文件
[root@localhost ~]# mv /usr/local/nginx/conf/vhost/load.conf
# 通过upstream来指定多个web服务器
upstream qq_com
{
# ip_hash的目的是让同一个客户始终保持在同一个机器上
ip_hash;

# 这里是负载均衡时使用的多个server的ip
# server http://61.135.157.157:80;
# 上述表示也行,对应的server块内的proxy_pass内直接写qq_com就可,不需要写http://
server 61.135.157.157:80;
server 125.39.240.113:80;
}
server
{
listen 80;
server_name www.qq.com;
location /
{
# 这里使用的是upstream名即qq_com
proxy_pass http://qq_com;
proxy_set_header Host $host;
proxy_set_header X_Real_IP $remote_addr;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
}
}

验证效果

配置未生效时,本地访问www.qq.com,得到的将是默认主机的内容

[root@localhost ~]# curl -x127.0.0.1:80 www.qq.com
this is default web server

重启服务后,获取到了www.qq.com网页的源码

[root@localhost ~]# /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
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# curl -x127.0.0.1:80 www.qq.com






??

if(window.location.toString().indexOf('pref=padindex') != -1){
}else{
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /\(Android.*Mobile.+\).+Gecko.+Firefox/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://xw.qq.com/index.htm";
}else if(/iPad/i.test(navigator.userAgent)){
//window.location.href="http://www.qq.com/pad/"
}else{
...

nginx不支持代理商https,即server语句内的端口无法使用443。


ssl原理

LNMP架构负载均衡及HTTPS相关配置

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » LNMP架构负载均衡及HTTPS相关配置

发表回复