1. 服務器
服務器選擇Linux的CentOS7的版本
2. 寶塔Linux面板
2.1 百度搜索寶塔
2.2 進去之后點擊立即免費安裝
2.3 選擇Linux在線安裝,輸入服務器信息進行安裝(也可以選擇其他方式)
安裝完成之后會彈一個寶塔的應用面板,并附帶有登錄名稱和密碼,這個要自己記下來的。
然后我們在瀏覽器打開這個面板,輸入剛剛的名稱和密碼就能登錄到該管理界面了。
3. 搭建Linux項目運行環境
3.1 創建MySql數據庫,保存用戶名和密碼,上傳sql文件并導入
3.2 安裝配置Redis
比如我的項目中用到了Redis,那就對應的再安裝一個Redis就行了呀,然后進行配置就可以。
我的項目中因為配置文件中沒有設置Redis的密碼和IP什么的,所以項目默認就會采用本機的Redis,其他的需要配置就配置沒有配置就用默認的配置就可以。
4. 部署Java項目
4.1 創建文件夾,上傳jar包
4.2 添加Java項目
4.2 啟動后端服務
4.2 添加Java項目
5. 部署Vue項目
5.1 上傳dist壓縮包,并解壓
5.2 第一種方式:通過nginx訪問
server {listen 80;server_name localhost;charset utf-8;location / {root /www/project/dist;index index.html index.htm;try_files $uri $uri/ /index.html;}location /accounting {alias /www/project/dist1;index index.html index.htm;try_files $uri $uri/ /index.html;}location /prod-api/ {proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:8081/;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}
}
5.2 第二種方式:選擇網站 -> PHP項目 -> 添加站點
1. 域名填寫公網ip(可以加上端口號)
2. 根目錄選擇解壓的dist
3. PHP版本選擇純靜態
5.3 修改配置文件
訪問前端頁面刷新出現404,添加下面代碼
location / {try_files $uri $uri/ /index.html;
}
添加接口路徑
location /api/ {proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:8081/;
}