0

I have a live server running django, the address is http://179.188.3.54/ . As you can see, the app works but looks like the static files arent working. Also if I click in any other link, doesnt work.

This website is running without any problems in development version. Im not sure what I should do to fix this problem.

Here is my nginx config file and my settings.py

STATIC_URL = '/static/'
STATIC_ROOT = '/cinegloria/cinegloria/cinegloria/static/'

PS: I tried to run collectstatic ;)

server {
    root /usr/share/nginx/www;
    index index.html index.htm;
    access_log /var/log/nginx/domain-access.log;
    server_name 0.0.0.0;

location / {
    try_files $uri $uri/ /index.html;
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-For  $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_connect_timeout 10;
    proxy_read_timeout 10;
    proxy_pass http://0.0.0.0:8000/;
}
}

Any ideas or sample code will be appreciated!

2 Answers 2

1

Add the static serving to the nginx conf before the / pattern:

location /static {
    alias /cinegloria/cinegloria/cinegloria/static/;
}

location / {
    ...
}

Or set the STATIC_ROOT to the directory under the www root:

STATIC_ROOT = '/usr/share/nginx/www/static'

Or add the symlink from www root to you static dir:

$ ln -s /cinegloria/cinegloria/cinegloria/static /usr/share/nginx/www/static
Sign up to request clarification or add additional context in comments.

3 Comments

Good one! It's working now. Your code is missing a ; in the end of alias line. Anyway, thanks for your answer. And about my pages, if I click in any link, is not working, it can be also nginx problem?
For example contact page, 179.188.3.54/contato ... any other page that I click, I get this error... [22/Feb/2015:23:50:37 -0300] "GET /contato/ HTTP/1.1" 404 1308 "179.188.3.54"
Try to comment the try_files directive. You don't need it for the regular django app.
1

Add another nginx directive for the static files. Static files should be served by nginx, not the Django server.

location  /static/ {
    alias  /cinegloria/cinegloria/cinegloria/static/;
}

If that still doesn't work, you may need to add the mime type directive. I had to do that yesterday, because for some reason nginx wasn't serving the correct mime type when I used an alias.

As a helpful pointer, whenever you run into problems like this, take a look at your nginx error log and paste the last few lines for debugging. It is located at /var/log/nginx/error.log or a similar path.

1 Comment

Do you know why my pages are broken? Seems like the links are not working. Is that a nginx problem ? do you know?

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.