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

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

xml 复制代码
# 配置工作进程的最大连接数
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.feituplan.com feituplan.com;
        # 重定向到HTTPS协议
        rewrite ^(.*)$ https://$host$1 permanent;
    }

    # 配置HTTPS协议
    server {
        # 监听默认的HTTPS端口
        listen 443 ssl;
        # 配置服务器名称
        server_name feituplan.com;

        # 配置SSL证书路径,如下图
        ssl_certificate cert/www.feituplan.com.pem;
        # 配置SSL证书的私钥路径,如下图
        ssl_certificate_key cert/www.feituplan.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://feituplan.com:8088"这个地址上
        location /map {
            # 反向代理到https://feituplan.com:8088
            proxy_pass https://feituplan.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://feituplan.com:8088"这个地址上
        location /image {
            # 反向代理到https://feituplan.com:8088
            proxy_pass https://feituplan.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://feituplan.com:8088"这个地址上
        location /feedback {
            # 反向代理到https://feituplan.com:8088
            proxy_pass https://feituplan.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;
        }
    }
}

证书存放位置,可自定义存放位置

两个文件


后端配置

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

yaml 复制代码
  ssl:
    key-store: www.feituplan.com.pfx # pfk存放路径
    key-store-type: PKCS12  # tomcat服务器类型默认
    key-store-password: htg72rfy # txt密码粘贴即可
相关推荐
阳洞洞2 小时前
https和http有什么区别
网络协议·http·https
云资源服务商3 小时前
解锁阿里云日志服务SLS:云时代的日志管理利器
服务器·阿里云·云计算
朱包林4 小时前
day45-nginx复杂跳转与https
linux·运维·服务器·网络·云计算
孙克旭_4 小时前
day045-nginx跳转功能补充与https
linux·运维·nginx·https
孞㐑¥5 小时前
Linux之Socket 编程 UDP
linux·服务器·c++·经验分享·笔记·网络协议·udp
柳鲲鹏6 小时前
WINDOWS最快布署WEB服务器:apache2
服务器·前端·windows
2501_915921438 小时前
iOS IPA 混淆实测分析:从逆向视角验证加固效果与防护流程
websocket·网络协议·tcp/ip·http·网络安全·https·udp
2501_915918418 小时前
打造可观测的 iOS CICD 流程:调试、追踪与质量保障全记录
websocket·网络协议·tcp/ip·http·网络安全·https·udp
bcbobo21cn9 小时前
初步了解Linux etc/profile文件
linux·运维·服务器·shell·profile
wayuncn10 小时前
月付物理服务器租用平台-青蛙云
运维·服务器·服务器租用·服务器托管·物理机租用