linux - nginx configuration content-type problem
高洛峰
高洛峰 2017-05-16 13:27:27
0
2
742

After the vue project is packaged, it generates a static directory and an index.html
Then I send these two files online

location / {
  try_files $uri $uri/ /index.html;
}

Through the above code, all routes defined in vue point to index.html
In this way, the website can be displayed, but the background json data cannot be obtained
The reasons are as follows:
Configuration in the mime_types file in nginx

type {
    text/html html
}
// 即所有后缀为html的文件的content-type都为text/html

Because all routes point to index.html, routes without suffix such as /api/articles point to index.html, so the response header content-type is text/html, but what I want to get is application/json

Please help me, thank you!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
巴扎黑

You can configure a location for the API that provides josn. I saw you asked me on Zhihu,
For example, location api/

phpcn_u1582
location /api {
    try_files $uri $uri/ /index.json;
}

But why do you need such a weird configuration...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template