title: Gunicorn on lighttpd - changing base URL for static files from localhost:8080
body: <p>Right now I'm working on Django project and this is my first time with running Django app on server (Lighttpd) via gunicorn. The problem is - I run application with gunicorn like this:</p>
  
  <pre><code>$PYTHON $MANAGEPATH run_gunicorn -D -b 127.0.0.1:18002 -p $GUNICORN_PIDPATH --log-file $GUNICORN_LOGPATH
  </code></pre>
  
  <p>Part of Django settings.py:</p>
  
  <pre><code>from __future__ import absolute_import
  
  import os
  from socket import gethostname
  
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  HOSTNAME = gethostname()
  
  def make_path(path):
      return os.path.join(BASE_DIR, path)
  
  # Absolute path to the directory static files should be collected to.
  # Don't put anything in this directory yourself; store your static files
  # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  # Example: "/var/www/example.com/static/"
  STATIC_ROOT = make_path('static_root')
  
  # URL prefix for static files.
  # Example: "http://example.com/static/", "http://static.example.com/"
  STATIC_URL = '/static/'
  </code></pre>
  
  <p>In /etc/lighttpd/vhost.d/my_conf.conf I have nice redirect for non-static files:</p>
  
  <pre><code>$SERVER["socket"] == ":82" {
      server.document-root = "/home/mefioo/public_html/generator/static"
      $HTTP["url"] !~ "\.(js|css|gif|jpg|png|ico|txt|swf|html|htm|svg|xlsx)$" {
          proxy.server = ("" =&gt; ( "localhost" =&gt; (
          "host" =&gt; "127.0.0.1",
          "port" =&gt; 18002,
          "fix-redirects" =&gt; 1
          ) ) )
      }
  }
  </code></pre>
  
  <p>Idea - static files like .js or .css are in </p>
  
  <pre><code>/home/mefioo/public_html/generator/static
  </code></pre>
  
  <p>(which is proxy to static_root dir in Django app) and should be avaiable from url like </p>
  
  <pre><code>my_domain.com:82/my_file.js
  </code></pre>
  
  <p>Rest of the app, with all the urls like this:</p>
  
  <pre><code>my_domain.com:82/url
  </code></pre>
  
  <p>should look for django app like that:</p>
  
  <pre><code>127.0.0.1:18002/url
  </code></pre>
  
  <p>because of lighttpd conf.</p>
  
  <p>The problem is - when I try to reach my static files, I got 404, because app is looking for </p>
  
  <pre><code>localhost:8080/my_file.js
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>my_domain.com:82/my_file.js
  </code></pre>
  
  <p>I don't understand why, especially when I have two instances of that app, one on my own server (second PC, doesn't work) and one on external VPS (works as intended). Am I running gunicorn wrong way, or missing something in lighttpd settings?</p>