參考“tomcat啟動前端項目”:https://www.cnblogs.com/mySummer/p/11167224.html 配置前端項目訪問的上下文:方法如下:
配置完成之后,打dist包:
然后配置nginx:
1 server { 2 listen 8089; 3 server_name localhost; 4 5 location /testTom/apis/ { //如果前端中訪問后台是/apis/后台訪問路徑,則這里配置:/apis/。 如果前端中訪問后台是/testTom/apis/,則這里配:/testTom/apis/
//代理結果:瀏覽器ip:port加上location后面的這個配置值====》替換成===》proxy_pass的值 6 proxy_pass http://localhost:8088/后台項目的context-path/; 7 } 8 9 location / { //此時訪問ip:port/testTome/能訪問項目根目錄 10 root D:\xxx\front; 11 } 12 13 }
效果:
前端ip:port/testTom/#/前端路徑,比如:localhost:8089/testTom/#/shouye 訪問vue首頁
前端ip:port/testTom/apis/后台具體controller訪問路徑,比如:localhost:8089/testTom/apis/testCon/testQuery。這個訪問等同於===后台ip:port/后台項目上下文/后台具體controller訪問路徑,比如:localhost:8080/studydemo/testCon/testQuery