title: 500 error with nginx loading django admin static files, but files load when making a request to the url
body: <p>I'm deploying a django web app to a nginx server running ubuntu</p>
  
  <p>When I try to log into the app, which uses the default django auth system, I get a "Server Error (500)" message rendered</p>
  
  <p>When I look at <code>/var/log/nginx/error.log</code> it shows the following message:</p>
  
  <pre><code>2016/10/11 22:35:53 [error] 16325#0: *42863 open()     "/path_to_app/app_name/static/admin/js/jquery.min.js" failed (2: No such file or directory), client: ip, server: _, request: "GET /static/admin/js/jquery.min.js HTTP/1.1", host: "domain_name.com", referrer: "http://nu-tab.me/accounts/login/?next=/"
  2016/10/11 22:35:53 [error] 16325#0: *42865 open() "/path_to_app/app_name/static/admin/js/jquery.init.js" failed (2: No such file or directory), client: ip, server: _, request: "GET /static/admin/js/jquery.init.js HTTP/1.1", host: "domain_name.com", referrer: "http://nu-tab.me/accounts/login/?next=/"
  2016/10/11 22:35:53 [error] 16325#0: *42866 open() "/path_to_app/app_name/static/admin/js/admin/RelatedObjectLookups.js" failed (2: No such file or directory), client: ip, server: _, request: "GET /static/admin/js/admin/RelatedObjectLookups.js HTTP/1.1", host: "domain_name.com", referrer: "domain_name.com/accounts/login/?next=/"
  </code></pre>
  
  <p>However, when I load <code>domain_name.com/static/admin/js/admin/RelatedObjectLookups.js</code>, the file loads properly.</p>
  
  <p>It's also worth noting that the <code>error.log</code> file has not been updated for recent requests.</p>
  
  <p>Not very familiar with setting up servers so let me know if there's important info here that I'm leaving out.</p>
  
  <p>nginx.conf:</p>
  
  <pre><code>user www-data;
  worker_processes 4;
  pid /run/nginx.pid;
  
  events {
      worker_connections 768;
      # multi_accept on;
  }
  
  http {
  
      ##
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
      # server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
      gzip_disable "msie6";
  
      # gzip_vary on;
      # gzip_proxied any;
      # gzip_comp_level 6;
      # gzip_buffers 16 8k;
      # gzip_http_version 1.1;
      # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # nginx-naxsi config
      ##
      # Uncomment it if you installed nginx-naxsi
      ##
  
      #include /etc/nginx/naxsi_core.rules;
  
      ##
      # nginx-passenger config
      ##
      # Uncomment it if you installed nginx-passenger
      ##
  
      #passenger_root /usr;
      #passenger_ruby /usr/bin/ruby;
  
      ##
      # Virtual Host Configs
      ##
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  </code></pre>
  
  <p>In sites-enabled/django:</p>
  
  <pre><code>    upstream app_server { 
          server 127.0.0.1:9000 fail_timeout=0; 
      } 
  
      server { 
          listen 80 default_server; 
          listen [::]:80 default_server ipv6only=on; 
  
          root /usr/share/nginx/html; 
          index index.html index.htm; 
  
          client_max_body_size 4G; 
          server_name _; 
  
          keepalive_timeout 5; 
  
          # your Django project's static files - amend as required 
          location /static/ { 
              alias /path_to_app/app_name/static/;  
          } 
  
          # your Django project's static files - amend as required
          location /media/ {
              alias /path_to_app/app_name/media/;
          }
  
          location / {
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_redirect off;
              proxy_pass http://app_server;
          }
      }
  </code></pre>
  
  <p>Relevant Django settings: </p>
  
  <pre><code>STATIC_URL = '/static/'
  STATIC_ROOT = '/path_to_app/app_name/static/'
  
  MEDIA_URL = '/media/'
  
  STATICFILES_DIRS = (
      os.path.join(BASE_DIR, 'app_name', 'static'),
  )
  </code></pre>