Serving static files with Nginx + Gunicorn + Django

前端 未结 2 1294
余生分开走
余生分开走 2020-12-08 17:28

This is my nginx config:

    server {
        listen 80;
        server_name localhost;

        keepalive_timeout 5;

        access_log /home/tunde/django-         


        
相关标签:
2条回答
  • 2020-12-08 17:43

    You need to create an nginx location block that matches the location of your django STATIC_URL. As you have it configured, nginx is also forwarding requests for static assets to your django application. I'm guessing you are seeing the 404 errors in your django application log? You want nginx to handle these requests, not django.

    location /static {
        alias /home/tunde/django-projects/mumu/STATIC/; 
    }
    

    Be sure to run the django admin command collectstatic to make sure all the static assets get copied to the STATIC_ROOT directory.

    0 讨论(0)
  • 2020-12-08 17:44
    location / {
        try_files $uri @proxy_to_app;
    }
    

    Please change $uri -> $request_uri

    location / {
        try_files $request_uri @proxy_to_app;
    }
    
    0 讨论(0)
提交回复
热议问题