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开发的单页应用,需要单独配置,但这种方式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都跳转到index.html
location / { error_page 404 /index.html; }
相关文章:
1. Android明明可以直接分享,为什么还要用微信开放平台、微博开放平台的sdk?2. javascript - 单页面应用怎么监听ios微信返回键?3. angular.js - 在ionic下,利用javascript导入百度地图,pc端可以显示,移动端无法显示4. nginx - 关于javaweb项目瘦身问题,前期开发后,发现项目占用存贮空间太大,差不多1.2个G,怎么实现瘦身,动态页面主要是jsp。5. css3 - 求教个问题,关于响应式布局,跟ipad有关,媒体查询失效?6. javascript - 如何保证几个ajax提交成功;7. css - 浏览器缩放分辨率为什么布局会变8. angular.js - 百度支持_escaped_fragment_吗?9. vue.js - vue apache 代理设置10. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?
