Nginx doesn't serve static

前端 未结 2 573
借酒劲吻你
借酒劲吻你 2020-12-08 05:16

I\'m running Django on Ubuntu Server 9.04.

Django works well, but nginx doesn\'t return static files - always 404.

Here\'s the config:

server         


        
相关标签:
2条回答
  • 2020-12-08 05:44

    I have a similar config for my Django sites, but I think you want to use alias instead of root for your media. For example:

    location /static {
        alias /home/user/www/oil/oil_database/static_files;
    }
    
    0 讨论(0)
  • 2020-12-08 05:46

    How is your directory setup? Do you have a folder static in /home/user/www/oil/oil_database/static_files? In that case, the directive should look like this (note the trailing slash in /static/):

    location /static/  {
        autoindex    on;
        root /home/user/www/oil/oil_database/static_files;
    }
    

    If you want to map the path /home/user/www/oil/oil_database/static_files to the URL /static/, you have to either

    • rename the folder static_files to static and use this directive:

      location /static/  {
          autoindex    on;
          root /home/user/www/oil/oil_database/;
      }
      
    • use an alias:

      location /static/  {
          autoindex    on;
          alias /home/user/www/oil/oil_database/static_files/;
      }
      

    See the documentation on the root and alias directives.

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