Fetching static files failed with 404 in nginx

后端 未结 2 1277
陌清茗
陌清茗 2021-02-01 04:50

I\'m now deploying an django app with nginx and gunicorn on ubuntu 12.

And I configure the nginx virtual host file as below:

server {
    listen 80;
             


        
相关标签:
2条回答
  • 2021-02-01 05:05

    TL;DR - you should check your files permissions

    Stumbled upon this question and I was already using alias instead of root, so while the existing answer was up to the point, the following could be useful to others.

    In my case, the solution to the same symptoms turned out to be the files in static/ having root as owner.

    A simple chown www-data:www-data . solved the problem, and no more 404.

    0 讨论(0)
  • 2021-02-01 05:14

    You should use alias instead of root. root appends the trailing URL parts to your local path (e.g. http://test.ndd/trailing/part, it will add /trailing/part to your local path). Instead of that, alias does exactly what you want: when http://test.ndd/static/ is requested, /static is mapped to your alias exactly, without appending static again.

    0 讨论(0)
提交回复
热议问题