• SpringBoot + Vue2项目打包部署到服务器后,使用Nginx配置SSL证书,配置访问HTTP协议转HTTPS协议


    配置nginx.conf文件,这个文件一般在/etc/nginx/...中,由于每个人的体质不一样,也有可能在别的路径里,自己找找...

    # 配置工作进程的最大连接数
    events {
        worker_connections 1024;
    }
    
    # 配置HTTP服务
    http {
        # 导入mime.types配置文件
        include mime.types;
        # 设置默认的MIME类型为application/octet-stream
        default_type application/octet-stream;
    
        # 配置HTTP协议,如果访问的端口为80,即HTTP协议,则跳转到HTTPS协议
        server {
            # 监听端口80
            listen 80;
            # 配置域名
            server_name www.feixxx.com feixxx.com;
            # 重定向到HTTPS协议
            rewrite ^(.*)$ https://$host$1 permanent;
        }
    
        # 配置HTTPS协议
        server {
            # 监听默认的HTTPS端口
            listen 443 ssl;
            # 配置域名
            server_name feixxx.com;
    
            # 配置SSL证书路径,如下图
            ssl_certificate cert/www.feixxx.com.pem;
            # 配置SSL证书的私钥路径,如下图
            ssl_certificate_key cert/www.feixxx.com.key;
            # 配置SSL会话缓存
            ssl_session_cache shared:SSL:1m;
            # 配置SSL会话超时时间
            ssl_session_timeout 5m;
            # 设置服务器端密码套件优先
            ssl_prefer_server_ciphers on;
    
            # 设置默认的索引文件
            index index.html;
            # Vue项目存放路径
            root /www/wwwroot/vue/html;
    
            location / {
                # 尝试匹配URL路径,如果找不到对应的文件,则重定向到index.html
                try_files $uri $uri/ /index.html;
            }
    
            #当请求中包含"/map"路径时,将请求转发到"https://feixxx.com:8088"这个地址上
            location /map {
                # 反向代理到https://feixxx.com:8088
                proxy_pass https://feixxx.com:8088;
                # 添加反向代理的请求头,并隐藏响应头中的X-Powered-By字段
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_hide_header X-Powered-By;
            }
    
            #当请求中包含"/image"路径时,将请求转发到"https://feixxx.com:8088"这个地址上
            location /image {
                # 反向代理到https://feixxx.com:8088
                proxy_pass https://feixxx.com:8088;
                # 添加反向代理的请求头,并隐藏响应头中的X-Powered-By字段
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_hide_header X-Powered-By;
            }
    
            #当请求中包含"/feedback"路径时,将请求转发到"https://feixxx.com:8088"这个地址上
            location /feedback {
                # 反向代理到https://feixxx.com:8088
                proxy_pass https://feixxx.com:8088;
                # 添加反向代理的请求头,并隐藏响应头中的X-Powered-By字段
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_hide_header X-Powered-By;
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84

    证书存放位置,可自定义存放位置
    在这里插入图片描述
    两个文件

    在这里插入图片描述

    后端配置
    把.pfx拷贝到resource下,然后配置一下yml

      ssl:
        key-store: www.feixxx.com.pfx # pfk存放路径
        key-store-type: PKCS12  # tomcat服务器类型默认
        key-store-password: htg72rfy # txt密码粘贴即可
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

  • 相关阅读:
    内存取证系列6
    前端面试那些事【dt/dd、audio、onerror、标签、类、ID选择器、伪类选择器......
    GJB 5000B二级-CM配置管理
    如何在 Vue 中使用 防抖 和 节流
    JVM垃圾回收器
    vector向量类使用
    做自动驾驶的同学看过来:场景理解、辅助功能、导航、寻路、避障数据集
    HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
    年薪26W+,入职外包公司三年,我是如何做到的?
    【wms平台化】一个简单的wms十表架构
  • 原文地址:https://blog.csdn.net/weixin_44912902/article/details/134224329