0

I am using nginx to serve my django static files. In the browser I can see that they are loaded, base.css, login.css, responsive.css all got status 200, I can click on them and see their content.

The problem is that they don't seem to be applied in the html. The html still looks like it has no css formatting applied to it at all. There are no errors in the nginx logs and no errors in the network tab in chrome. I have tried chrome and firefox

Using Django 2.2.4

Relevant nginx config

server {
    listen          8000;
    server_name     127.0.0.1;

    location /static/ {
        autoindex on;
        alias /home/ubuntu/<SECRET_PATH>/static/;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/<SECRET_PATH>/dashboard.sock;
    }
}
6
  • can you check if the static url is correct in your django application? Commented Aug 14, 2019 at 5:45
  • If you are running collectstatic and still it doesn't work (like you said that CSS files load), does the server return proper mime types for CSS files? Commented Aug 14, 2019 at 5:46
  • @Rehmat I see in chrome that the type is stylesheet Commented Aug 14, 2019 at 5:47
  • @ruddra I assume its correct since nginx is serving those files to the browser Commented Aug 14, 2019 at 5:48
  • @Dale Can you mention the URL if the site isn't private? Commented Aug 14, 2019 at 5:50

2 Answers 2

5

Based on your comment, it looks like proper mime type isn't returned for the CSS files. In your NGINX conf, generally it is located at /etc/nginx/nginx.conf, ensure that you have included the mimes like:

include "/etc/nginx/mime.types";

And in your mimes, ensure that proper mime type is set for the CSS files.

Sign up to request clarification or add additional context in comments.

Comments

1

After checking the response headers I saw the mime type was text (as @Rehmat suggested). The fix was to add the mime types in the server block

include /etc/nginx/mime.types;

this solved the problem

1 Comment

Glad, just posted the answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.