springboot+nginx+https+linux实现负载均衡加域名访问简单测试

时间:2023-03-10 07:50:54
springboot+nginx+https+linux实现负载均衡加域名访问简单测试
  1. 把springboot项目打包成三个jar包,并指定端口为
    14341,14342,14343
  2. 下载腾讯云免费ssl证书,解压后会出现如下图文件夹

    springboot+nginx+https+linux实现负载均衡加域名访问简单测试

  3. 把nginx文件夹下的 .crt 和 .key文件复制到服务器,例如复制到
    /home/ssl/xxx.crt
    /home/ssl/xxx.key
  4. 安装好nginx默认配置文件在
    /usr/local/nginx/conf/nginx.conf
  5. 修改nginx.conf配置文件实现https+负载均衡的简单测试(此测试是在一台服务器上面进行)
    worker_processes  1;
    
    events {
    worker_connections 1024;
    } http {
    include mime.types;
    default_type application/octet-stream; sendfile on;
    keepalive_timeout 65; upstream paint {
    server 127.0.0.1:14341 weight=2;
    server 127.0.0.1:14342 weight=1;
    server 127.0.0.1:14343 weight=1;
    } server {
    listen 443 ssl;
    server_name www.xxx.com xxx.com;
    ssl_certificate /home/ssl/xxx.crt;
    ssl_certificate_key /home/ssl/xxx.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    location / {
    proxy_pass http://paint;
    }
    } server {
    listen 80;
    server_name www.xxx.com xxx.com;
    rewrite ^(.*)$ https://${server_name}$1 permanent;
    }
    }
  6. 以上nginx.conf配置文件即可实现,理论上来说weight设置的数值越大,访问到的机率就会越大
  7. 在linux上后台运行第一步准备的jar包
    nohup java -jar xx01-0.0.1-SNAPSHOT.jar >/home/log/logs1.txt &
    nohup java -jar xx02-0.0.1-SNAPSHOT.jar >/home/log/logs2.txt &
    nohup java -jar xx03-0.0.1-SNAPSHOT.jar >/home/log/logs3.txt &
  8. 查看后台运行的任务
    jobs