title: Django static files with nginx and unicorn
body: <p>I'm trying to deploy my django application to my VPS. So I followed several tutorials and the only issue i'm having is that I can't get my static files to show up. So below you can find the structure of my files on the VPS.</p>
  
  <ul>
  <li>Virtual Env: /opt/myapps/</li>
  <li>Django project: /opt/myapps/uniprogress/</li>
  <li>Static Files: /opt/myapps/uniprogress/static/</li>
  </ul>
  
  <p>Nginx config: /etc/nginx/sites-available/uniprogress</p>
  
  <pre><code>server {
      server_name 188.xxx.xxx.93;
  
      access_log off;
  
      location /static/ {
          alias /opt/myapps/uniprogress/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"';
      }
  }
  </code></pre>
  
  <p>and finally in my django settings.py:</p>
  
  <pre><code># Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  
  import os
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  
  # Template Dirs
  
  TEMPLATE_DIRS = (
      os.path.join(SETTINGS_PATH, 'templates'),
  )
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.6/howto/static-files/
  
  STATIC_ROOT = '/opt/myapps/uniprogress/static/'
  STATIC_URL = '/static/'
  </code></pre>
  
  <p>I also used: <code>python manage.py collectstatic</code> but still my static files won't show up.</p>
  
  <p><strong>UPDATE</strong>
  The tutorial I used can be found at <a href="https://www.digitalocean.com/community/articles/how-to-deploy-a-local-django-app-to-a-vps" rel="nofollow">Digital Ocean</a>.</p>
  
  <p>I double checked that the files exist on the server.</p>
  
  <p>Also I can access static files like: <a href="http://188.xxx.xxx.93/static/css/bootstrap.css" rel="nofollow">http://188.xxx.xxx.93/static/css/bootstrap.css</a>.</p>
  
  <p><strong>BUT</strong> In my source code <a href="http://188.xxx.xxx.93:8001/" rel="nofollow">http://188.xxx.xxx.93:8001/</a>, it links static files using the port.</p>
  
  <p>That means: <code>&lt;link href="/static/css/bootstrap.css" rel="stylesheet"&gt;</code></p>
  
  <p>So it tries to find bootstrap.css at <a href="http://188.xxx.xxx.93" rel="nofollow">http://188.xxx.xxx.93</a><strong>:8001</strong>/static/bootstrap.css and the file doesn't exist(have to remove the post to make it work).</p>