search

Home  >  Q&A  >  body text

linux - nginx configuration content-type problem

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!

高洛峰高洛峰2809 days ago733

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 13:29:27

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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:29:27

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

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

    reply
    0
  • Cancelreply