vue.js - vue-router開啟HTML5的history模式后nginx配置
問題描述
因為在eagle201510項目下面有很多子項目,嘗試了多種配置方法都不能共存
我希望是這樣的:
server {listen 80;server_name 192.168.10.91;root 'E:/UED/eagle/branch/eagle201510';location / { index index.html index.htm index.php; #autoindex on;}location ^~ /m-example/ { root 'E:/UED/eagle/branch/eagle201510/m-example'; try_files $uri $uri/ /index.html =404;}location ~ .php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; includefastcgi_params;}}
m-example目錄是使用vue-router開發(fā)的單頁應(yīng)用,需要單獨配置,但這種方式m-example并不能正常加載加載的js,css都變成了htmlconsole
vendors.js:1 Uncaught SyntaxError: Unexpected token <main.js:1 Uncaught SyntaxError: Unexpected token <index.html:6 Resource interpreted as Stylesheet but transferred with MIME type text/html: 'http://192.168.10.91/m-example/dist/main.css'.
如果配置改成這樣:
server {listen 80;server_name 192.168.10.91;root 'E:/UED/eagle/branch/eagle201510';location / { root 'E:/UED/eagle/branch/eagle201510/m-example'; try_files $uri $uri/ /index.html =404;}location ~ .php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; includefastcgi_params;}}
就正常了。但是其它項目又無法訪問了。。。
問題解答
回答1:添加一個server配置項解決,如下:
server {listen 80;server_name www.m-example.com;root 'E:/UED/eagle/branch/eagle201510/m-example';location / { try_files $uri $uri/ /index.html =404;}}回答2:
把所有沒有后綴名的請求如果404都跳轉(zhuǎn)到index.html
location / { error_page 404 /index.html; }
相關(guān)文章:
1. 淺談vue生命周期共有幾個階段?分別是什么?2. javascript - 安裝了babel,不起作用3. html5 - vue項目中我用webpack編譯不成功4. css - 如何實現(xiàn)單行與多行文字的居中5. macos - mac下docker如何設(shè)置代理6. html5 - 純CSS怎么做出這種一模一樣的導(dǎo)航條導(dǎo)航塊那里還有個下拉菜單,請大家指導(dǎo)一下7. node.js - Angular-webpack-Starter, 怎么把NodeJS添加進項目里?8. index.php錯誤,求指點9. 微信公眾號在線生成二維碼帶參數(shù)怎么搞?10. 微信開放平臺 - android 微信支付后點完成按鈕,后回調(diào)打開第三方頁面,屏幕閃動,求解決方法
