title: Nginx -- static file serving confusion with root & alias
body: <p>I need to serve my app through my app server at <code>8080</code>, and my static files from a directory without touching the app server.</p>
  <pre><code>    # app server on port 8080
      # nginx listens on port 8123
      server {
              listen          8123;
              access_log      off;
  
              location /static/ {
                      # root /var/www/app/static/;
                      alias /var/www/app/static/;
                      autoindex off;
              }
  
  
              location / {
                      proxy_pass              http://127.0.0.1:8080;
                      proxy_set_header        Host             $host;
                      proxy_set_header        X-Real-IP        $remote_addr;
                      proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
              }
      }
  </code></pre>
  <p>Now, with this config, everything is working fine. Note that the <code>root</code> directive is commented out.</p>
  <p>If I activate <code>root</code> and deactivate the <code>alias</code>, it stops working. However, when I remove the trailing <code>/static/</code> from <code>root</code>, it starts working again.</p>
  <p>Can someone explain what's going on?</p>