2

Updated Code - this is still not working though.

Settings.py

STATIC_ROOT = '/home/ubuntu/virtualenv/mysite/homelaunch/static/'
STATIC_URL = '/static/'

nginx conf :: /etc/nginx/sites-enabled/mysite

server {
        server_name ec2-x-x-x-x.compute-1.amazonaws.com;
        access_log /home/ubuntu/virtualenv/mysite/error/access.log;
        error_log /home/ubuntu/virtualenv/mysite/error/error.log warn;
        connection_pool_size 2048;

        location /static/ {
            #alias /home/ubuntu/virtualenv/mysite/homelaunch/static/;
            #alias /static/;
            root /home/ubuntu/virtualenv/mysite/homelaunch/;
        }

        location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #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"';
        }
    }

gunicorn config -

command = '/usr/local/bin/gunicorn'
logfile = "/home/ubuntu/virtualenv/mysite/error/gunicorn.log"
loglevel = "info"
pythonpath = '/home/ubuntu/virtualenv/mysite'
bind = '127.0.0.1:8001'

full path to img dir and css dir:

/home/ubuntu/virtualenv/mysite/homelaunch/static/css
/home/ubuntu/virtualenv/mysite/homelaunch/static/img

Receiving an error in the error.log:

001/favicon.ico", host: "ec2-xx-xx-xx-xx.compute-1.amazonaws.com"
2013/09/02 16:57:42 [error] 2819#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: ec2-xx-xx-xx-xx.compute-1.amazonaws.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "ec2-xx-xx-xx-xx.compute-1.amazonaws.com"

Anything that is glaringly wrong? I'm still getting a 404 error on both img and css files when I try to view them through the outputted html source.

user700070
  • 153
  • 3
  • 8
  • The configuration seems fine to me, does the file `/home/ubuntu/virtualenv/mysite/homelaunch/img/templated/base/LogoV1.png` actually exist ? – Changaco Sep 01 '13 at 14:51
  • No it doesn't. /home/ubuntu/virtualenv/mysite/homelaunch/static/img/templated/base/LogoV1.png does . This is missing the `static` dir after `homelaunch` dir . So what do I have to modify? If you could please specify in an answer I will try it out – user700070 Sep 01 '13 at 14:54
  • Does `STATIC_ROOT = '/mysite/homelaunch/'` have to change to: `STATIC_ROOT = '/mysite/homelaunch/static/'` ? – user700070 Sep 01 '13 at 14:57
  • additionally, i tried this as well ^^ and it didnt fix anything. It ALWAYS loads the template, but will not load the static files: img, css, etc . – user700070 Sep 01 '13 at 15:26
  • yeah I've run this portion of it already too – user700070 Sep 01 '13 at 15:43
  • Okay, I fixed that. Code updated. it seems to be definitely throwing a http404 error now when i click the on css link within the html source outputted - it didnt before, butStill no images or css working though. I also verified that '/home/ubuntu/virtualenv/mysite/homelaunch/static/' is accessible and it is. Any thought? – user700070 Sep 01 '13 at 16:32
  • I'm getting an error in error.log as specified in nginx config of: 2013/09/01 03:33:37 [alert] 2689#0: accept4() failed (24: Too many open files) - any idea? . I also just turned on DEBUG in settings.py - nothing new at least on output – user700070 Sep 01 '13 at 17:02
  • This error is potentially unrelated to the problem i am having – user700070 Sep 01 '13 at 17:03
  • DEBUG is turned on. I get the basic 404 page served by django. It throws an error with the urls.py . It says it can't find a path to use for http://ec2-x-x-x-x.compute-1.amazonaws.com:8001/static/img/templated/base/LogoV1.png , do I have to specify a regex for all of these directories, like: /img/templated/base/, /img/templated/home in urls.py? To serve all of the directories for static files? – user700070 Sep 01 '13 at 17:26
  • am I missing any required settings on nginx that you can think of? – user700070 Sep 01 '13 at 18:25

2 Answers2

1

This answer has been edited to summarize the solutions.

In the configuration of nginx

Replacing:

alias /home/ubuntu/virtualenv/mysite/homelaunch/;

with:

root /home/ubuntu/virtualenv/mysite/homelaunch/;

See the documentation for more details.

Replacing:

proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;

with:

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

In gunicorn's config

Replacing:

bind = 'ec2-x-x-x-x.compute-1.amazonaws.com:8001'

with:

bind = '127.0.0.1:8001'

In django's settings

Setting STATIC_ROOT = '/home/ubuntu/virtualenv/mysite/homelaunch/static/' which is the correct absolute filesystem path.

Setting DEBUG = True to have more detailed error information.

Changaco
  • 880
  • 5
  • 10
0

Replace this:

location /static/ {
            alias /home/ubuntu/virtualenv/mysite/homelaunch/;
        }

For this one:

location /static/ {
            alias  /home/ubuntu/virtualenv/mysite/homelaunch/static/;
}

If you do a alias you need put absolute path, because you have defined static dir on settings.py

STATIC_URL = '/static/'

So if you put alias this dir /home/ubuntu/virtualenv/mysite/homelaunch/;

Nginx think the statics files are on /home/ubuntu/virtualenv/mysite/homelaunch/ and not in /home/ubuntu/virtualenv/mysite/homelaunch/static

Sorry for my bad english, i try to improve :(

I hope you understand me.

Skamasle
  • 422
  • 2
  • 10
  • This does the same thing as replacing `alias` by `root`, so it won't help more than my answer. – Changaco Sep 01 '13 at 16:06
  • Not is the same, because on django he have defindes satatic files on /static/ so if change alias for correct dir stil work, he have alias defines for orther dir not for statics: location /static/ { alias /home/ubuntu/virtualenv/mysite/homelaunch/; } So this solution is if he have their statics on /home/ubuntu/virtualenv/mysite/homelaunch/statics – Skamasle Sep 01 '13 at 16:12
  • @Skamasle - please see updated code and give your thoughts. I would really appreciate it – user700070 Sep 01 '13 at 16:40
  • So and now working ? May point is only than you need define the alias on same dir when you have statics.., so I hope that works if not give us some lines of your error logs, and your dir distribution so what are on /home/ubuntu/virtualenv/mysite/homelaunch/ and on /home/ubuntu/virtualenv/mysite/ and on what dir you have your statics etc I have a django setup for some of my clients whit similar alias, and work very well. – Skamasle Sep 01 '13 at 18:08
  • @Skamasle - what do you need from me? – user700070 Sep 02 '13 at 01:05
  • So you still have the problem whit images ? give us your error log, last lines on paste bin, and give us also path dir when you have your static content, your images or template. – Skamasle Sep 02 '13 at 18:15