Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 !

share|improve this question

3 Answers 3

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;
share|improve this answer
The first line you mentionned is part of the nginx configuration file recommended in the digitalocean tutorial, I just copied/pasted it. What you have suggested didn't change anything. Is it an nginx of django problem ? Should nginx serve the files on port 8001 or should django serve files from instead of ? – Simon Jun 9 '14 at 2:47
this worked for me thanks. – HassenPy Sep 15 at 13:08

First ensure that you have debug disabled in your

DEBUG = False

Check your path to static files and url (ex.)

`STATIC_URL = '/static/'

STATICFILES_DIRS = { "/home/myproject/static/", }`

Define your static url in nginx (ex):

location /static/ { alias /home/myproject/static/; expires 1d; }

share|improve this answer

Is not django problem at, but nginx proxy configuration

The problem is quite similar to this one: (I paste link directly as it is an internal link on serverfault, don't want to duplicate answers)

Removing port from nginx redirect

Maybe even adding proxy_redirect off; to the location configuration does the trick.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.