jeecg-boot 3.1.0版本 https的部署


對jar部署方式 單服務端 接口配置https

 

1、將證書文件導入項目中

 

 

 

2、配置application-prod.yml文件

server:
  port: 443
  ssl:
    enabled: true
    key-store: classpath:z******.jks
    key-password: hderdefef**ddd
    key-store-type: JKS

說明:

port:SSL監聽的端口443

key-store:證書的完整路徑,如上圖已經導入到項目中,前面一定要加classpath:標志

key-password:證書密碼,keystorePass.txt中的內容。

key-store-type:證書類型,我用的是JKS

 

3、這里配置完成后,修改pom.xml文集,排除jks文件

 代碼

<resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>xxxxxxx.jks</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>xxxxxxx.jks</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.json</include>
                    <include>**/*.ftl</include>
                </includes>
            </resource>
        </resources>

現在服務端的接口服務就配置完成了,直接在maven中對應install和package打包出來.jar文件部署即可

最后在服務端運行 java -jar jeecg-boot******.jar 能看到如下界面,就說明服務端部署沒毛病

 

4、前端部署,修改.env.production中的相關配置:

 

5、前端的配置文件:nginx.conf

按照官方的配置基本沒問題,需要修改部分地方,參看一個網友他的配置是這樣的:

server {
    listen 3000 ssl;
    server_name xxx.xxx.cn;
    
    ssl_certificate /opt/server.crt;
    ssl_certificate_key /opt/server.key;
 
    #后台服務配置,配置了這個location便可以通過http://域名/jeecg-boot/xxxx 訪問        
    location ^~ /jeecg-boot {
        proxy_pass              https://localhost:443/jeecg-boot/;
        proxy_set_header        Host localhost;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    #解決Router(mode: 'history')模式下,刷新路由地址不能找到頁面的問題
    location / {
        root   /opt/gdsapp/HHGC_dashboard/html/dist;
        index  index.html index.htm;
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.html?s=$1 last;
            break;
        }
    }
}

按照他這個配置下來,大體沒啥問題,就是每次請求頭是http,而不是https,這就導致無法真實的訪問到服務端的接口地址,因為現在服務端接口地址是:https://xxx.xxx.cn/jeecg-boot/

所有需要修改一下配置文件,做一個重定向,讓他進行代理跳轉到https服務接口下:最終版本就成了這樣:

 

  server {
   listen 443;
   server_name xxx.xxx.cn;
   return 301 https://$http_host$request_uri;
   access_log  off;
   }

    server {
        listen       3000;
        server_name xxx.xxx.cn; 

       ssl_certificate /opt/server.crt;
       ssl_certificate_key /opt/server.key;

        #后台服務配置,配置了這個location便可以通過http://域名/jeecg-boot/xxxx 訪問        
        location ^~ /jeecg-boot {
            proxy_pass              https://localhost:443/jeecg-boot/;
            proxy_set_header        Host localhost;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        #解決Router(mode: 'history')模式下,刷新路由地址不能找到頁面的問題
        location / {
            root   html;
            index  index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.html?s=$1 last;
                break;
            }
        }

      }

 

最終無BUG運行OK!!!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM