node.js - 如何在服務(wù)器部署vuejs項(xiàng)目?
問(wèn)題描述
vue-cli搭建的環(huán)境,http://localhost:8080/comment...訪問(wèn)沒(méi)問(wèn)題,我現(xiàn)在想通過(guò)http://bxu2348550081.my3w.com...訪問(wèn)同樣的數(shù)據(jù),是在打包編譯前配置還是在服務(wù)器配置?
問(wèn)題解答
回答1:配置一個(gè)服務(wù)器指向你的dist文件就可以
我用的nginx
server { listen port; server_name your.host.name; rewrite_log on; charset utf8; root /home/path/xxxxx; index index.html;client_max_body_size 100m;access_log /home/xxxx/access.log ; error_log /home/xxxx/error.log; location ~* .(html)$ { root /home/path/xxxxx; etag on;expires 30d;index index.html; } gzip on; # 啟用gzip壓縮的最小文件,小于設(shè)置值的文件將不會(huì)壓縮 gzip_min_length 1k; # gzip 壓縮級(jí)別,1-10,數(shù)字越大壓縮的越好,也越占用CPU時(shí)間,后面會(huì)有詳細(xì)說(shuō)明 gzip_comp_level 6; # 進(jìn)行壓縮的文件類型。javascript有多種形式。其中的值可以在 mime.types 文件中找到。 gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml; # 是否在http header中添加Vary: Accept-Encoding,建議開啟 gzip_vary on; # 禁用IE 6 gzip gzip_disable 'MSIE [1-6].'; location ~* .(css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|map|mp4|ogg|ogv|webm|htc)$ { root /home/path/xxxxx; index index.html; expires 1M; access_log off; add_header Cache-Control 'public'; } }回答2:
vue build之后吧dist里面的文件,丟上服務(wù)器就可以了
回答3:看來(lái)你使用的是html5 history模式了,部署的話需要處理一下訪問(wèn)路徑的問(wèn)題,然后把網(wǎng)站文件夾指向dist目錄就好了
參考https://router.vuejs.org/zh-c...
相關(guān)文章:
1. python - django orm 過(guò)濾日期為當(dāng)天日期的數(shù)據(jù)2. nginx - pip install python庫(kù)報(bào)錯(cuò)3. mysql里的大表用mycat做水平拆分,是不是要先手動(dòng)分好,再配置mycat4. 老師您的微信號(hào)是多少?5. window下mysql中文亂碼怎么解決??6. mysql - 數(shù)據(jù)庫(kù)如何存儲(chǔ)小說(shuō)數(shù)據(jù)比較好?7. python - (初學(xué)者)代碼運(yùn)行不起來(lái),求指導(dǎo),謝謝!8. mysql - 5千萬(wàn)文章,怎么做相關(guān)文章?9. 為什么python中實(shí)例檢查推薦使用isinstance而不是type?10. mysql如何添加索引的時(shí)候指定索引方式
