title: Use nginx to serve static files from subdirectories of a given directory
body: <p>I have several sets of static <code>.html</code> files on my server, and I would like use nginx to serve them directly. For example, nginx should serve an URI of the following pattern:</p>
  
  <pre><code>www.mysite.com/public/doc/foo/bar.html
  </code></pre>
  
  <p>with the <code>.html</code> file that is located at <code>/home/www-data/mysite/public/doc/foo/bar.html</code>. You can think of <code>foo</code> as the set name, and <code>bar</code> as the file name here.</p>
  
  <p>I wonder whether the following piece of nginx config would do the job:</p>
  
  <pre><code>server {
      listen        8080;
      server_name   www.mysite.com mysite.com;
      error_log     /home/www-data/logs/nginx_www.error.log;
      error_page    404    /404.html;
  
      location /public/doc/ {
          autoindex         on;
          alias             /home/www-data/mysite/public/doc/;
      }
  
      location = /404.html {
          alias             /home/www-data/mysite/static/html/404.html;
      }
  }
  </code></pre>
  
  <p>In other words, all requests of the pattern <code>/public/doc/.../....html</code> are going to be handled by nginx, and if any given URI is not found, a default <code>www.mysite.com/404.html</code> is returned. </p>