vue.js - vue-router開(kāi)啟HTML5的history模式后nginx配置
問(wèn)題描述
因?yàn)樵趀agle201510項(xiàng)目下面有很多子項(xiàng)目,嘗試了多種配置方法都不能共存
我希望是這樣的:
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開(kāi)發(fā)的單頁(yè)應(yīng)用,需要單獨(dú)配置,但這種方式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;}}
就正常了。但是其它項(xiàng)目又無(wú)法訪問(wèn)了。。。
問(wèn)題解答
回答1:添加一個(gè)server配置項(xiàng)解決,如下:
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:
把所有沒(méi)有后綴名的請(qǐng)求如果404都跳轉(zhuǎn)到index.html
location / { error_page 404 /index.html; }
相關(guān)文章:
1. css - C#與java開(kāi)發(fā)Windows程序哪個(gè)好?2. mysql無(wú)法添加外鍵3. css - 定位為absolute的父元素中的子元素 如何設(shè)置在父元素的下面?4. java - Mybatis查詢數(shù)據(jù)庫(kù)時(shí)出現(xiàn)查詢getInt()的錯(cuò)誤5. JavaScript事件6. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境7. javascript - es6將類數(shù)組轉(zhuǎn)化成數(shù)組的問(wèn)題8. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?9. css3 - flex 父標(biāo)簽設(shè)置align-item:center,子元素flex:1,不起作用10. java - 是否類 類型指針、引用作為形參 ,函數(shù)結(jié)束不會(huì)自動(dòng)析構(gòu)類?
