nginx发布vue打包的项目遇到的问题

最近我把之前开发的vue项目打包发布到linux服务器,就这个简单的事情,我遇到了各种坑,记录一下问题,方便日后查看

  1. 发布之后,无法访问css样式

Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://47.105.187.153:91/static/css/app.0457f95e9c3d0f3c39017fc8e529dbf5.css".

google的报错信息
原因是在nginx的配置中未添加mime.types,在nginx.conf中添加下面两行默认配置就可以解决

include mime.types;
default_type application/octet-stream;

  1. nginx发布之后,vue-router会在刷新的时候失效
    我是用的是history模式,为了好看,为了避免失效的情况,需要在nginx的配置总增加一行

server {
listen 91;
server_name localhost;
location / {
root cschool;
index index.html;
try_files $uri $uri/ /index.html;
}
}

try_files $uri $uri/ /index.html; 添加后就可以避免上述问题

  1. 上传文件的时候,超过限制大小

POST http://47.105.187.153:92/vschool/imgAdd 413 (Request Entity Too Large)

我的天,还是配置的问题,nginx.conf增加默认的配置

client_max_body_size 8M;
client_body_buffer_size 128k;

你可能感兴趣的:(nginx发布vue打包的项目遇到的问题)