jeecg-boot 3.1.0版本 https的部署
阿新 • • 發佈:2022-04-20
對jar部署方式 單服務端 介面配置https
1、將證書檔案匯入專案中
2、配置application-prod.yml檔案
server: port: 443 ssl: enabled: true key-store: classpath:zhangbin1993.top.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>zhangbin1993.top.jks</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>zhangbin1993.top.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!!!!