0

I am setting up an environment with a django application (askbot opensource project), gunicorn and nginx. With nginx and gunicorn in different docker containers.

This is my nginx configuration.

server {
       listen 80;

       location /static {
         alias /askbot/static;
       }

       location /m {
         alias /askbot/static;
       }

       location / {
         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_pass http://askbot:8080/;
       }
     }

If I run the django app on debug mode, everything is ok, I can go through nginx and I see how nginx is only invoking gunicorn for the dynamic content, and the static content is resolved locally.

But, when I run the django application with debug false, nginx does not revolve the static content, and if I see the source code for the web page, I can see all the paths for the static content have changed, using somethign like "/m/CACHE...". I guess this is the reason why nginx cannot resolve the static content anymore.

For example, when using debug mode equals true, this is one fragment of the html source code.

<link rel="stylesheet" href="/m/CACHE/css/9275d0e5b87f.css" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans+Condensed:700&amp;subset=latin-ext" rel="stylesheet" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans+Condensed:700&amp;subset=cyrillic-ext" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/m/default/media/jslib/modernizr.custom.js?v=1"></script> <script type="text/javascript">

And when running with debug equals false, the same fragment is like.

<link href="/m/default/media/style/style.css?v=1" rel="stylesheet" type="text/css" /> <link href="/m/default/media/fa-4.3.0/css/font-awesome.css?v=1" rel="stylesheet" type="text/css" /> <link href="/m/default/media/bootstrap/css/bootstrap.css?v=1" rel="stylesheet" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans+Condensed:700&amp;subset=latin-ext" rel="stylesheet" type="text/css" /> <link href="//fonts.googleapis.com/css?family=Open+Sans+Condensed:700&amp;subset=cyrillic-ext" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/m/default/media/jslib/modernizr.custom.js?v=1"></script> <script type="text/javascript">

I have been going around this for two days, could anyone explain to me why is that happening and how can be fixed ?, configuring nginx on a different way, or disabling django to have that behaviour.

Thanks in advance, Esteban Collado

Esteban Collado
  • 1,840
  • 1
  • 14
  • 15
  • have you looked at [link](https://docs.djangoproject.com/en/dev/howto/static-files/)? and `run python manage.py collectstatic` – James Birkett Oct 03 '19 at 17:28
  • Hi @JamesBirkett yes, I looked at it. Anyway, I was able to solve my problem, The issue was the compressor app which was responsible for the behaviour I had, I disabled the compression adding to the settings.py file COMPRESS_ENABLED = False. – Esteban Collado Oct 04 '19 at 07:22

1 Answers1

0

Ok, I was able to solve my problem,

It was caused by the compressor application included in the settings.py file.

INSTALLED_APPS = (
...
    'compressor'
...
)

The django application I was deploying needed that application, so what I did was disable the compression adding to the same file.

   COMPRESS_ENABLED = False

Now, I do not see the behaviour I described in my question, all the static filed added to the CACHE folder in the urls.

BR, Esteban Collado

Esteban Collado
  • 1,840
  • 1
  • 14
  • 15