一、ECS 服务器
1. 购买 ECS
2. 配置安全组
开放端口:
443
、22
、80
、8080
、3306
二、RDS 数据库
1. 购买 RDS
2. 导入测试数据
三、在 ESC 服务器运行项目
1. 修改参数
2. 生成 jar 包并上传到服务器
3. 安装 JDK
4. 运行项目
nohup java -jar BuGuBlogDemo-0.0.1-SNAPSHOT.jar > ./blog.log 2>&1 &
5. 管理项目
# 查看项目日志
cat /root/bugu.log
# 查找服务的 pid
ps -ef | grep "java -jar"
# 杀掉相关的进程即可结束项目的运行
kill -9 3551
6. 浏览器访问测试
http://IP:8080/Blog/page/front/index.html
四、配置域名解析
1. 准备域名
2. 添加 A 记录
3. 浏览器访问验证
http://www.bugu-blog.top:8080/Blog/page/front/index.html
五、配置 Nginx 负载均衡
1. 重新创建一个新的服务器
在新服务器中运行项目
nohup java -jar BuGuBlogDemo-0.0.1-SNAPSHOT.jar > ./blog.log 2>&1 &
2. 购买 ELB
3. 添加监听器
4. 修改域名解析指向 ELB 的 EIP
5. 测试
六、使用 HTTPS 协议访问项目
1. 申请免费的 SSL 证书
创建测试证书 | 点击申请证书
2. 进行 DNS 验证
添加一条 txt 记录,具体参数在第一步中有给出
3. 下载证书到本地
4. 安装 nginx
yum install -y nginx
5. 上传证书到服务器
6. 修改 nginx.conf 参数
vim /etc/nginx/nginx.conf
server {
listen 443 ssl;
server_name www.bugu-blog.top; # 1. 域名
ssl_certificate /root/ssl/server.crt; # 2. crt 文件的位置
ssl_certificate_key /root/ssl/server.key; # 3. key 文件的位置
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://IP:8080; # 4. 将请求地址转发到 http://IP:8080
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Upgrade-Insecure-Requests 1;
proxy_set_header X-Forwarded-Proto https;
}
}
7. 浏览器访问验证
https://www.bugu-blog.top/Blog/page/front/index.html