Django fails to find static files served by nginx

Simon asked:

I know this is a really noobish question but I can’t find any solution despite finding the problem trivial.

I have a django application deployed with gunicorn. The static files are served by the nginx server with the following url : However, my django application keep looking for the static files at and is obviously failing (404).

I don’t know how to fix this. Is it a django or an nginx problem ? Here is my nginx configuration file :

server {

    access_log off;

    location /static/ {
        alias /home/myproject/static/;

    location / {
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';

Thanks for the help !

My answer:

I don’t know why you have this in your configuration. It doesn’t do anything.

        proxy_set_header X-Forwarded-Host $server_name;

Anyway, you are not passing on the Host header, which is the most likely reason I can think of why your URLs are being mangled.

Try setting that:

        proxy_set_header Host $http_host;

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.