Linux:网站HTTPS认证+负载均衡

要求

部署https,要求访问之前所有站点都通过负载均衡来访问

https://www.xx.com
https://upload.xx.com
https://download.xx.com
https://blog.xx.com
https://zhihu.xx.com
https://game.xx.com

环境

角色IP主机名
web服务器10.0.0.7web01
web服务器10.0.0.8web02
负载均衡172.16.1.5lb01

web0、web02

  • 准备站点目录与文件
[root@web01 ~]# tree -L 1 /web
/web
├── download
├── h5game
├── kaoshi
├── mysqli.php
├── wordpress
├── www
└── zhihu
  • 编写配置文件
vim /etc/nginx/conf.d/test.conf
server{
        server_name game.yjs.com;
        listen 80;
        root /web/h5game;
        index index.html;
        access_log logs/h5game-access.log;
        error_log logs/h5game-error.log;
}

server{
	server_name www.yjs.com;
	listen 80;
	root /web/www;
	index index.html;
	access_log logs/www-access.log;
	error_log logs/www-error.log;
}

server{
	server_name download.yjs.com;
	listen 80;
	root /web/download;
	index index.html;
	
	location / {
		autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
	}
	location /status{
		stub_status;
		access_log off;
		auth_basic "access auth,input your password!";
		auth_basic_user_file /etc/nginx/auth_conf;
	}
}


server{
	server_name upload.yjs.com;
	listen 8080;
	root /web/kaoshi;
	index index.php index.html;

	location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
 	}
}

server{
	server_name blog.yjs.com;
	listen 80;
	root /web/wordpress;
	index index.php indx.html;

	location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
 	}

	location /status{
		stub_status;
		access_log off;
	}
}

server{
	server_name zhihu.yjs.com;
	listen 80;
	root /web/zhihu;
	index index.php indx.html;

	location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
 	}

	location /status{
		stub_status;
		access_log off;
	}
}

lb01

  • 编辑站点优化配置文件
vim /etc/nginx/proxy_params
#代理服务器会携带用户的http请求头部中域名主机信息
proxy_set_header Host $http_host;
#记录真实客户端的IP地址,写在日志的$http_x_forwarded_for变量里
proxy_set_header X-Real-IP $remote_addr;
#客户端通过代理服务访问后端服务, 后端服务通过该变量会记录真实客户端地址
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#代理与后端服务器连接超时时间
proxy_connect_timeout 30;
#后端服务器数据回传给nginx代理超时时间
proxy_send_timeout 60;
#nginx代理等待后端服务器的响应时间
proxy_read_timeout 60;

#开启缓冲区,先放到缓冲区当中,然后再返回给客户端,边收边传
proxy_buffering on;
#保存用户头信息的缓冲区大小为32K
proxy_buffer_size 32k;
#设置缓冲区的大小和数量
proxy_buffers 4 128k;

  • 负载均衡
vim /etc/nginx/conf.d/proxy.conf
upstream www {
	server 10.0.0.7:80;
	server 10.0.0.8:80;
}
server {
	listen 80;
	server_name www.yjs.com;
	location / {
		proxy_pass http://www;
		#proxy_params为站点优化配置文件
		include proxy_params;
	}
}

server {
        listen 80;
        server_name upload.yjs.com;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        listen 80;
        server_name download.yjs.com;
        location / {
                proxy_pass http://www; 
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        listen 80;
        server_name blog.yjs.com;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        listen 80;
        server_name zhihu.yjs.com;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        listen 80;
        server_name game.yjs.com;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

部署HTTPS

  1. 创建证书存放目录
mkdir -p /etc/nginx/cert
  1. 准备申请的证书
unzip -d /etc/nginx/cert/ cert.zip
  1. 编辑lb01配置文件
upstream www {
	server 10.0.0.7:80;
	server 10.0.0.8:80;
}
server {
	server_name www.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
	location / {
		proxy_pass http://www;
		#proxy_params为站点优化配置文件
		include proxy_params;
	}
}

server {
        server_name upload.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        server_name download.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
        location / {
                proxy_pass http://www; 
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        server_name blog.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        server_name zhihu.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}

server {
        server_name game.yjs.com;
	listen 443 ssl;
	charset utf-8,gbk;
	client_max_body_size 20M;
	ssl_certificate cert/3114201_www.tfantastic.com.pem;
	ssl_certificate_key cert/3114201_www.tfantastic.com.key;
	ssl_session_timeout 5m;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
	ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
        location / {
                proxy_pass http://www;
                #proxy_params为站点优化配置文件
                include proxy_params;
        }
}
  1. 图示
https://www.yjs.com/

在这里插入图片描述

https://upload.yjs.com/

在这里插入图片描述

https://download.yjs.com/

在这里插入图片描述

https://zhihu.yjs.com/

在这里插入图片描述

https://game.yjs.com/

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Lazy-Balancer 项目起源于好哥们需要一个 7 层负载均衡器,无奈商业负载均衡器成本高昂,操作复杂。又没有特别喜欢(好看,好用)的开源产品,作为一名大 Ops 怎么能没有办法?正好最近在看 Django 框架,尝试自己给 Nginx 画皮,项目诞生!非专业开发,代码凑合看吧。 项目基于 Django   AdminLTE 构建,在 Ubuntu 14.04 上测试通过;为了保证良好的兼容性,请使用 Chrome 浏览器。 因为增加了 iptables 自动控制,所以暂时不支持 docker 方式部署;需要本地测试的同学请使用 vagrant 方式 为了后续扩展方便,请大家使用 Tengine 替代 Nginx 服务 项目地址 GITHUB - https://github.com/v55448330/lazy-balancer 码云 - http://git.oschina.net/v55448330/lazy-balancer OSCHINA - http://www.oschina.net/p/nginx-balancer 更新 将 Nginx 更换为 Tengine 以提供更灵活的功能支持以及性能提升 新增 HTTP 状态码方式检测后端服务器,默认 TCP 方式 新增 HTTP 状态码方式支持查看后端服务器状态 修复因前方有防火墙导致无法获取后端服务器状态 修复因主机头导致后端服务器探测失败 新增自定义管理员用户 新增配置通过文件备份和还原 新增实时查看访问日志和错误日志 新增实时请求统计 更新 Vagrantfile 修复其他 Bug 功能 Nginx 可视化配置 Nginx 负载均衡(反向代理)配置 Nginx 证书支持 系统状态监测 自动维护防火墙规则(白名单) 支持 TCP 被动后端节点宕机检测 支持 HTTP 主动后端节点宕机检测 运行 克隆代码 mkdir -p /app git clone https://github.com/v55448330/lazy-balancer.git /app/lazy_balancer cd /app/lazy_balancer 卸载 nginx apt-get -y purge nginx-* nginx* apt-get -y autoremove 安装 tengine git submodule update --init --recursive cd resource/nginx/tengine apt-get install -y build-essential libssl-dev libpcre3 libpcre3-dev zlib1g-dev ./configure --user=www-data --group=www-data --prefix=/etc/nginx --sbin-path=/usr/sbin --error-log-path=/var/log/nginx/error.log --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx.pid make make install mkdir -p /etc/nginx/conf.d echo "daemon off;" >> /etc/nginx/nginx.conf 安装 supervisor apt-get install supervisor update-rc.d supervisor enable 配置 supervisor cp -rf service/* /etc/supervisor/ 安装依赖 apt-get install -y python-dev python-pip iptables libcurl4-openssl-dev pip install -r requirements.txt 初始化数据库 python manage.py makemigrations python manage.py migrate 启动服务 service supervisor restart
### 回答1: 阿里云提供了 Apsara Clouder 云计算专项技能认证,其中包括了云服务器 ECS 入门的内容。云服务器 ECS 是一种属于阿里云的计算服务,它能够通过网络提供计算能力,使得用户可以快速地创建和管理云服务器。 在阿里云平台上,我们可以使用资源管理器或者控制台创建自己的云服务器 ECS。首先,我们需要选择适合自己的规格和操作系统。无论是 Windows 还是 Linux,都有适合不同场景的规格供我们选择。 创建完云服务器 ECS 之后,我们需要了解如何进行基础的配置和操作。登录到云服务器 ECS 后,我们可以进行系统的初始化设置、安全设置、以及网络设置等操作。此外,我们需要学习如何通过公网和内网访问云服务器 ECS,以及如何在云服务器 ECS 中部署和运行应用程序。 此外,云服务器 ECS 还提供了许多高级的功能,如负载均衡、自动化运维、容器化部署等。针对这些高级功能,我们需要深入了解云计算和云服务器 ECS 的相关知识,才能够进行有效的部署和管理。 总之,云服务器 ECS 入门是 Apsara Clouder 云计算专项技能认证的一部分,它能够帮助用户快速了解云计算和云服务器 ECS 的基本知识,从而在云计算领域中具备竞争力。 ### 回答2: Apsara Clouder云计算专项技能认证的云服务器ECS入门是一个非常有用的课程,它可以帮助学习者掌握阿里云服务器的基础知识和使用方法。在这个课程中,学习者可以学到如何购买和配置服务器ECS,以及如何管理和维护其操作系统和应用程序。此外,学习者还可以学习到如何将云服务器与其他阿里云服务进行集成,如云盘、负载均衡和CDN等。 通过学习这个课程,学习者可以建立一个基本的云计算环境,将其用于网站搭建、应用开发、备份存储和数据分析等方面。在学习课程的过程中,学习者可以通过实际操作来加深对云计算的理解和掌握阿里云服务器ECS的使用。此外,学习者还可以与其他学习者交流,分享彼此的经验和技巧。 总的来说,Apsara Clouder云计算专项技能认证的云服务器ECS入门是一门很实用的课程,它可以帮助学习者快速入门阿里云服务器ECS,掌握云计算的基础知识和使用方法,在云计算领域中迅速成长。同时,它还为学习者提供了一个与其他学习者交流和分享的平台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值