日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

SpringBoot + Vue + nginx项目一起部署

發布時間:2025/3/21 vue 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot + Vue + nginx项目一起部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SpringBoot + Vue + nginx項目一起部署

SpringBoot + Vue 一起部署到?nginx

1.后端項目部署:

(1)? Java項目打包上傳到 服務器,開啟服務

java -jar *****.jar --server.port=8080

(2)? vue項目打包,拷貝dist下的static和index.html到/usr/local/nginx/html目錄下

? (3)? ? ?安裝Nginx,參考https://blog.csdn.net/qq_22027637/article/details/81776092,安裝好后配置nginx,打開/usr/local/nginx/conf/nginx.conf,配置如下:

?
  • events {

  • worker_connections 1024;

  • }

  • ?
  • ?
  • http {

  • include mime.types;

  • default_type application/octet-stream;

  • sendfile on;

  • ?
  • keepalive_timeout 65;

  • ?
  • server {

  • listen 80;

  • server_name localhost;

  • ?
  • # 404頁面跳轉

  • location / {

  • try_files $uri /index.html;

  • }

  • ?
  • # 靜態資源目錄,即vue打包后的dist里的靜態資源

  • root /usr/local/nginx/html;

  • index index.html index.htm;

  • ?
  • # 后端服務的配置

  • location /api/ {

  • proxy_redirect off;

  • proxy_set_header Host $host;

  • proxy_set_header X-Real-IP $remote_addr;

  • proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  • # 后端服務地址

  • proxy_pass http://localhost:8080/;

  • }

  • ?
  • ?
  • error_page 500 502 503 504 /50x.html;

  • location = /50x.html {

  • root html;

  • }

  • }

  • ?
  • }

  • (4)輸入ip地址或域名即可訪問

    ?

    ?

    ----------------------------------

    ?

    1.nginx安裝參照https://blog.csdn.net/qq_22027637/article/details/81776092

    2.將springboot項目打包上傳到服務器,開啟服務

    啟動springboot項目可以用二種方式:(1)nohup java -jar demo.jar &

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (2)nohup java -jar demo.jar & > log.file 2>&1 &

    3.vue項目打包上傳到服務器:? npm run build

    打包后會生成靜態頁面,在項目根路徑的dist文件夾下面,將該文件夾移到服務器的某個目錄下,我這里是/root/ncp

    4.修改nginx配置文件,配置文件默認是/usr/local/nginx/conf/nginx.conf

  • location / {

  • root /root/vueproject/dist; //vue項目部署路徑

  • try_files $uri $uri/ /index.html last; //解決頁面刷新404問題

  • index index.html index.htm;

  • }

  • 另外在nginx配置文件nginx.conf頭部加上user root;

    重啟nginx,進入/usr/local/nginx/sbin

    ./nginx -s reload

    訪問http://ip:nginx端口號,例如http:127.0.0.1/9000,即可訪問頁面,至此vue項目前臺就部署完成了

    再次修改nginx配置文件nginx.conf,在nginx.conf中增加

  • ?
  • location /manager/ {

  • proxy_pass http://127.0.0.1:9006/; //springboot項目端口

  • }

  • 重啟nginx

    訪問http://ip:nginx端口號,即可實現與后臺交互

    ?

    總結

    以上是生活随笔為你收集整理的SpringBoot + Vue + nginx项目一起部署的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。