vue項(xiàng)目nginx二級(jí)域名配置方式
vue項(xiàng)目nginx二級(jí)域名配置
1、將vue項(xiàng)目路由的加入base配置如下圖所示,打包備用
2、配置nginx,下圖所示
3、在步驟2中的nginx的根目錄下面html文件夾下面新增data文件夾,在data下面新建vue和test文件夾,將步驟1打包的文件放到vue文件夾和test文件夾,訪問(wèn)本地http://localhost/test/和http://localhost/vue/
nginx多個(gè)vue項(xiàng)目使用獨(dú)立二級(jí)域名部署
因?yàn)轫?xiàng)目前后端分離部署,多個(gè)項(xiàng)目前端使用同一個(gè)nginx發(fā)布,每個(gè)項(xiàng)目對(duì)應(yīng)不同的二級(jí)域名
- dsp項(xiàng)目 : dsp.xxxx.com
- bi項(xiàng)目:bi.xxxx.com
1. 在vue.config.js文件下找到publicPath配置,添加如下配置(vuecli2就是config文件夾下的assetsPublicPath配置)
publicPath: process.env.NODE_ENV === "production" ? "/bi/" : "/bi/",
2.修改項(xiàng)目router的base
export default new Router({ ? mode: 'history', // 去掉url中的# ? base: '/bi/', ? scrollBehavior: () => ({ y: 0 }), ? routes: constantRoutes })
3.修改.env.production
##這個(gè)地方改成每個(gè)項(xiàng)目不一樣就行了 VUE_APP_BASE_API = '/prod'
4.然后將項(xiàng)目打包
將打包好的文件放到指定目錄下
5.配置nginx
首先修改nginx.conf
# For more information on configuration, see: # ? * Official English Documentation: http://nginx.org/en/docs/ # ? * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { ? ? worker_connections 1024; } http { ? ? log_format ?main ?'$remote_addr - $remote_user [$time_local] "$request" ' ? ? ? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" ' ? ? ? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"'; ? ? access_log ?/var/log/nginx/access.log ?main; ? ? sendfile ? ? ? ? ? ?on; ? ? tcp_nopush ? ? ? ? ?on; ? ? tcp_nodelay ? ? ? ? on; ? ? keepalive_timeout ? 65; ? ? types_hash_max_size 2048; ? ? include ? ? ? ? ? ? /etc/nginx/mime.types; ? ? default_type ? ? ? ?application/octet-stream; ? ? # Load modular configuration files from the /etc/nginx/conf.d directory. ? ? # See http://nginx.org/en/docs/ngx_core_module.html#include ? ? # for more information. ? ? include /etc/nginx/conf.d/*.conf; ? ? #這個(gè)地方是我自己建了一個(gè)目錄,兩個(gè)項(xiàng)目分別在這個(gè)目錄下建自己的配置文件 ? ? include /etc/nginx/custom/*.conf; ? ? server { ? ? ? ? listen ? ? ? 80 default_server; ? ? ? ? listen ? ? ? [::]:80 default_server; ? ? ? ? server_name ?dsp.xxxx.com; ? ? ? ? root ? ? ? ? /usr/share/nginx/html; ? ? ? ? # Load configuration files for the default server block. ? ? ? ? include /etc/nginx/default.d/*.conf; ?? ?location / { ? ? ? ? } ? ? ? ? error_page 404 /404.html; ? ? ? ? ? ? location = /40x.html { ? ? ? ? } ? ? ? ? error_page 500 502 503 504 /50x.html; ? ? ? ? ? ? location = /50x.html { ? ? ? ? } ? ? } # Settings for a TLS enabled server. # # ? ?server { # ? ? ? ?listen ? ? ? 443 ssl http2 default_server; # ? ? ? ?listen ? ? ? [::]:443 ssl http2 default_server; # ? ? ? ?server_name ?_; # ? ? ? ?root ? ? ? ? /usr/share/nginx/html; # # ? ? ? ?ssl_certificate "/etc/pki/nginx/server.crt"; # ? ? ? ?ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ? ? ? ?ssl_session_cache shared:SSL:1m; # ? ? ? ?ssl_session_timeout ?10m; # ? ? ? ?ssl_ciphers HIGH:!aNULL:!MD5; # ? ? ? ?ssl_prefer_server_ciphers on; # # ? ? ? ?# Load configuration files for the default server block. # ? ? ? ?include /etc/nginx/default.d/*.conf; # # ? ? ? ?location / { # ? ? ? ?} # # ? ? ? ?error_page 404 /404.html; # ? ? ? ? ? ?location = /40x.html { # ? ? ? ?} # # ? ? ? ?error_page 500 502 503 504 /50x.html; # ? ? ? ? ? ?location = /50x.html { # ? ? ? ?} # ? ?} }
dsp.conf
? ? server { ? ? ? ? listen ? ? ? 80; ? ? ? ? server_name ?dsp.xxxx.com; ?? ??? ?location / { ?? ??? ??? ?try_files $uri $uri/ /index.html; ? ? ? ? ? ? #dsp項(xiàng)目目錄 ?? ??? ??? ?root ? /soft/dpf/web; ? ? ? ? ? ? index ?index.html index.htm; ? ? ? ? } ?? ??? ?#prod-api是代理的路徑 ?? ??? ?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; ? ? ? ? ? ? ##后端服務(wù)的地址 ?? ??? ??? ?proxy_pass http://localhost:20001/; ?? ??? ?} ? ? ? ? error_page ? 500 502 503 504 ?/50x.html; ? ? ? ? location = /50x.html { ? ? ? ? ? ? root ? html; ? ? ? ? } ? ? }
bi.conf
? ? server { ? ? ? ? listen ? ? ? 80; ? ? ? ? server_name ?bi.xxxx.com; ? ? ? ? root /soft/bi/ui; ?? ?location /bi/ { ?? ? ? ?try_files $uri $uri/ /index.html; ? ? ? ? } ?? ?location /prod/{ ?? ??? ?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:30001/; ? ? ? ? } ? ? ? ? error_page ? 500 502 503 504 ?/50x.html; ? ? ? ? location = /50x.html { ? ? ? ? ? ? root ? html; ? ? ? ? } ? ? }?? ?
然后執(zhí)行nginx -s reload 重新加載nginx配置即可
備注:因?yàn)関ue打包將index.html中css,圖片的路徑都加了publicPath這個(gè)參數(shù)值,在訪問(wèn)頁(yè)面會(huì)出現(xiàn)找不到資源的情況,這種情況下,只需要在你的項(xiàng)目目錄下創(chuàng)建這個(gè)路徑,然后將static目錄拷貝進(jìn)去即可
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于Element-UI中slot的用法及說(shuō)明
這篇文章主要介紹了關(guān)于Element-UI中slot的用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10Vue腳手架搭建及創(chuàng)建Vue項(xiàng)目流程的詳細(xì)教程
Vue腳手架指的是vue-cli,它是一個(gè)快速構(gòu)建**單頁(yè)面應(yīng)用程序(SPA)**環(huán)境配置的工具,cli是(command-line-interfac)命令行界面,下面這篇文章主要給大家介紹了關(guān)于Vue腳手架搭建及創(chuàng)建Vue項(xiàng)目流程的相關(guān)資料,需要的朋友可以參考下2022-09-09vue style width a href動(dòng)態(tài)拼接問(wèn)題的解決
這篇文章主要介紹了vue style width a href動(dòng)態(tài)拼接問(wèn)題的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08vuex 中輔助函數(shù)mapGetters的基本用法詳解
mapGetters輔助函數(shù)僅僅是將 store 中的 getter 映射到局部計(jì)算屬性,在組件或界面中不使用mapGetter調(diào)用映射vuex中的getter,在組件或界面中使用mapGetter調(diào)用映射vuex中的getter,具體內(nèi)容跟隨小編一起通過(guò)本文學(xué)習(xí)吧2021-07-07vue3.0實(shí)踐之寫tsx語(yǔ)法實(shí)例
很久不寫博客了,最近在使用ts和tsx開發(fā)vue類項(xiàng)目,網(wǎng)上資料比較少,順便記錄一下方便同樣開發(fā)的人互相學(xué)習(xí)共同進(jìn)步,下面這篇文章主要給大家介紹了關(guān)于vue3.0實(shí)踐之寫tsx語(yǔ)法的相關(guān)資料,需要的朋友可以參考下2022-07-07