Can't figure out why my Static Files won't load

141 views
Skip to first unread message

Kyle Pennell

unread,
Mar 27, 2014, 5:46:24 PM3/27/14
to mezzani...@googlegroups.com
Triple checked my settings and can't find why my static files aren't loading.

Nginx and Gunicorn are installed and working.
Symbolic Link between sites-available and sites-enabled is made

── sites-available
│   ├── mezzanine_app
│   └── myproject
├── sites-enabled
│   ├── ahalearning -> ../sites-available/ahalearning
│   ├── mezzanine_app -> ../sites-available/mezzanine_app
│   └── myproject -> ../sites-available/myproject


Collectstatic has been run and static files are in place:

├── deploy
│   ├── crontab
│   ├── gunicorn.conf.py
│   ├── live_settings.py
│   ├── nginx.conf
│   └── supervisor.conf
├── dev.db
├── fabfile.py
├── __init__.py
├── __init__.pyc
├── local_settings.py
├── local_settings.pyc
├── manage.py
├── requirements.txt
├── settings.py
├── settings.pyc
├── static
│   ├── admin
│   ├── css
│   ├── filebrowser
│   ├── fonts
│   ├── grappelli
│   ├── img
│   ├── js
│   ├── media
│   ├── mezzanine
│   ├── robots.txt
│   └── test
├── urls.py
├── urls.pyc
└── wsgi.py


STATIC_ROOT in settings.py points to the right folder (opt/myenv/mezzanine_app/static/)


My nginx server settings point to the right files: 
/etc/nginx/sites-available

 server {
        server_name 107.170.215.138;

        access_log off;

        location /static/ {
            alias  /opt/myenv/mezzanine_app/static/;
        }

        location / {
                proxy_pass http://127.0.0.1:8001;
                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"';
        }
    }
Nginx and Gunicorn fire up without problems.



Any idea what I might be missing?

Why are my static files 404'ing?


Stephen McDonald

unread,
Mar 27, 2014, 7:28:41 PM3/27/14
to mezzani...@googlegroups.com
I think this will look for the directory "/opt/myenv/mezzanine_app/static/static/"

 



        location / {
                proxy_pass http://127.0.0.1:8001;
                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"';
        }
    }
Nginx and Gunicorn fire up without problems.



Any idea what I might be missing?

Why are my static files 404'ing?


--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen McDonald
http://jupo.org

Kyle Pennell

unread,
Mar 27, 2014, 7:32:10 PM3/27/14
to mezzani...@googlegroups.com
Ah!  Will try pulling that out.  Thanks for the help, Stephen.


--
You received this message because you are subscribed to a topic in the Google Groups "Mezzanine Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mezzanine-users/CrUlR8jjUw0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mezzanine-use...@googlegroups.com.

Matthew Summers

unread,
Mar 27, 2014, 10:45:04 PM3/27/14
to mezzani...@googlegroups.com
Remove the trailing slash on your location alias directive.
M. Summers

"...there are no rules here -- we're trying to accomplish something."
- Thomas A. Edison

Kyle Pennell

unread,
Mar 28, 2014, 2:35:39 PM3/28/14
to mezzani...@googlegroups.com
Thanks for responding.

Double checking I understand:

   location /static/ {
            alias  /opt/myenv/mezzanine_app/static/;
        }
Should be:
   location /static/ {
            alias  /opt/myenv/mezzanine_app/static;
        }
Or?

   location /static/ {
            alias  /opt/myenv/mezzanine_app;
        }

Kyle Pennell

unread,
Mar 28, 2014, 2:41:57 PM3/28/14
to mezzani...@googlegroups.com
Tried each combo and none worked...hmmm...

Kyle Pennell

unread,
Mar 28, 2014, 2:51:42 PM3/28/14
to mezzani...@googlegroups.com
Nginx Error Log:

2014/03/28 12:16:12 [error] 13768#0: *27 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.70, server: 107.170.215.138:8001, request: "GET

Now to try to figure out what these are saying:

2014/03/28 07:12:58 [error] 13768#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.146, server: 107.170.215.138:8001, request: "GET$

2014/03/28 07:28:45 [error] 13768#0: *10 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.147, server: 107.170.215.138:8001, request: "GE$

2014/03/28 07:32:54 [error] 13768#0: *12 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.140, server: 107.170.215.138:8001, request: "GE$

2014/03/28 07:45:33 [error] 13768#0: *14 connect() failed (111: Connection refused) while connecting to upstream, client: 220.181.51.147, server: 107.170.215.138:8001, request: "GE$

2014/03/28 07:49:52 [error] 13768#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 81.171.52.4, server: 107.170.215.138:8001, request: "GET h$

2014/03/28 07:52:08 [error] 13768#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 189.114.248.181, server: 107.170.215.138:8001, request: "H$

2014/03/28 07:53:24 [error] 13768#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.70, server: 107.170.215.138:8001, request: "GET$

2014/03/28 08:11:36 [error] 13768#0: *23 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.198, server: 107.170.215.138:8001, request: "GE$

2014/03/28 11:58:37 [error] 13768#0: *25 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.70, server: 107.170.215.138:8001, request: "GET$

2014/03/28 12:16:12 [error] 13768#0: *27 connect() failed (111: Connection refused) while connecting to upstream, client: 61.135.190.70, server: 107.170.215.138:8001, request: "GET$

$t: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8001/", host: "107.170.215.138", referrer: "http://www.baidu.com/s?wd=www"

2014/03/28 12:50:56 [error] 13768#0: *31 connect() failed (111: Connection refused) while connecting to upstream, client: 18.242.7.117, server: 107.170.215.138:8001, request: "HEAD$

2014/03/28 14:06:02 [error] 13768#0: *33 connect() failed (111: Connection refused) while connecting to upstream, client: 202.53.8.82, server: 107.170.215.138:8001, request: "GET 


$t: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8001/", host: "107.170.215.138", referrer: "http://www.baidu.com/s?wd=www"

Matthew Summers

unread,
Mar 28, 2014, 4:48:01 PM3/28/14
to mezzani...@googlegroups.com
On Fri, Mar 28, 2014 at 1:35 PM, Kyle Pennell <kpen...@gmail.com> wrote:
> Thanks for responding.
>
> Double checking I understand:
>
> location /static/ {
> alias /opt/myenv/mezzanine_app/static/;
> }
>
> Should be:
>
> location /static/ {
> alias /opt/myenv/mezzanine_app/static;
> }
>
> Or?
>
> location /static/ {
> alias /opt/myenv/mezzanine_app;
> }
>
>

You'll want this one assuming the mezz project layout where your
static dir is directly under your messanine_app dir:

location /static/ {
alias /opt/myenv/mezzanine_app;
}


As far as your error log, it looks like you might need to add the
static ip of your server to ALLOWED_HOSTS in settings. Your app server
is refusing to respond to nginx.

Cheers,
Matt

Kyle Pennell

unread,
Mar 28, 2014, 9:20:15 PM3/28/14
to mezzani...@googlegroups.com
First off, thanks so much for taking the time to respond to another beginner.  I'm on tutorial number 5 now of trying to figure this out.  I'm amazed I haven't yet.  What a challenge.

Changed that file:

server {
        server_name 107.170.215.138;
        access_log off;
        location /static/ {
            alias /opt/myenv/mezzanine_app;

        }
        location / {
                proxy_pass http://127.0.0.1:8001;
                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"';
        }
    }


My static ip was in the allowed hosts:

ALLOWED_HOSTS = [
        '107.170.215.138',
        '107.170.215.138.',
]


Error logs are the same.


If you happen to have any random ideas, they'd be very much appreciated.

Kyle

Luc Milland

unread,
Mar 29, 2014, 4:00:08 AM3/29/14
to mezzani...@googlegroups.com
could this be firewall related ?

Le vendredi 28 mars 2014 à 18:20 -0700, Kyle Pennell a écrit :
> First off, thanks so much for taking the time to respond to another
> beginner. I'm on tutorial number 5 now of trying to figure this out. I'm
> amazed I haven't yet. What a challenge.
>
> Changed that file:
>
> server {
> > server_name 107.170.215.138;
> > access_log off;
> > location /static/ {
> > alias /opt/myenv/mezzanine_app;
> > }
> > location / {
> > proxy_pass http://127.0.0.1:8001;
> > 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"';
> > }
> > }
> >
> >
> My static ip was in the allowed hosts:
>
> ALLOWED_HOSTS = [
> > '107.170.215.138',
> > '107.170.215.138.',
> > ]
>
>
>
> Error logs are the same.
>
>
> If you happen to have any random ideas, they'd be very much appreciated.
>
> Kyle
>
> On Friday, March 28, 2014 2:48:01 PM UTC-6, Matthew Summers wrote:
> >
> > On Fri, Mar 28, 2014 at 1:35 PM, Kyle Pennell <kpen...@gmail.com<javascript:>>

Kyle Pennell

unread,
Mar 31, 2014, 7:52:31 PM3/31/14
to mezzani...@googlegroups.com
This is on Digital Ocean.  How would I check out firewall related issues?

Jesse Carrigan

unread,
Apr 1, 2014, 1:58:43 AM4/1/14
to mezzani...@googlegroups.com
Rather than the IP address of the host, have you tried your live hostname (e.g. "www.example.com" or "example.com")? My sites are hosted on Digital Ocean and that's what needed to be in the ALLOWED_HOSTS list. Same for the server_name in the ngnix configs.

Kyle Pennell

unread,
Apr 1, 2014, 1:34:24 PM4/1/14
to mezzani...@googlegroups.com
Hey Jesse,
Thanks for looking over this.

Ok, so you had to change it to an actual domain then?  Did you do the whole DNS redirect and everything to setup that domain with your digital ocean IP?

Jesse Carrigan

unread,
Apr 1, 2014, 1:43:44 PM4/1/14
to mezzani...@googlegroups.com
Correct, my DNS records on Digital Ocean are set up as follows (I'm faking some of the information here):

A record: @ 192.168.123.123

example.com is in the ALLOWED_HOSTS list.

It sounds like you may not have a domain associated with the droplet, though? Is that the case?

Kyle Pennell

unread,
Apr 1, 2014, 2:03:50 PM4/1/14
to mezzani...@googlegroups.com
Yes, no domain associated.  Was just hoping to work with the ip address. Thanks for the response.  Any chance you have your working file on github?  I've been stuck for 2 weeks now and would love to see it.


--
Message has been deleted

Jesse Carrigan

unread,
Apr 1, 2014, 3:35:15 PM4/1/14
to mezzani...@googlegroups.com
I don't have it on github, but it basically follows the pattern of the deploy/ngnix.conf file in the mezzanine project. Here's what it looks like:

upstream example {
    server 127.0.0.1:8001;
}

server {
    listen 80;
    listen 443 ssl;
    server_name example.com;
    client_max_body_size 10M;
    keepalive_timeout    15;

    ssl_certificate      conf/example.crt;
    ssl_certificate_key  conf/example.key;
    ssl_session_cache    shared:SSL:10m;
    ssl_session_timeout  10m;
    ssl_ciphers RC4:HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_redirect      off;
        proxy_set_header    Host                    $host;
        proxy_set_header    X-Real-IP               $remote_addr;
        proxy_set_header    X-Forwarded-For         $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Protocol    $scheme;
        proxy_pass          http://example;
    }

    location /static/ {
        root            home/admin/.virtualenvs/example/project/;
        access_log      off;
        log_not_found   off;
    }

    location /robots.txt {
        root            home/admin/.virtualenvs/example/project/static;
access_log off; log_not_found off; } location /favicon.ico { root home/admin/.virtualenvs/example/project/static/img;
access_log off; log_not_found off; } }

Jesse Carrigan

unread,
Apr 1, 2014, 3:38:12 PM4/1/14
to mezzani...@googlegroups.com
Just out of curiosity, are you using fabric to deploy your site or are you editing the config by hand?

Also, a couple of things I found helpful in trying to get the static files going:


Kyle Pennell

unread,
Apr 1, 2014, 3:52:32 PM4/1/14
to mezzani...@googlegroups.com
I'm going to try Fabric next. I was trying to the Digital Ocean Tuts to try to get this but no dice.


--

Jesse Carrigan

unread,
Apr 1, 2014, 3:55:14 PM4/1/14
to mezzani...@googlegroups.com
As a piece of encouragement, it took me about the same amount of time struggling with it to make it work, but after getting things set up correctly it's really easy to successfully deploy with Fabric. I'd recommend it; it's a much more repeatable process.

Kyle Pennell

unread,
Apr 1, 2014, 3:55:45 PM4/1/14
to mezzani...@googlegroups.com
Thanks, Jesse.  Much appreciated.


On Tue, Apr 1, 2014 at 1:55 PM, Jesse Carrigan <jesse.m....@gmail.com> wrote:
As a piece of encouragement, it took me about the same amount of time struggling with it to make it work, but after getting things set up correctly it's really easy to successfully deploy with Fabric. I'd recommend it; it's a much more repeatable process.

--
Reply all
Reply to author
Forward
0 new messages