title: nginx - How do I serve an index file on a subfolder?
body: <p>I'm trying to host a jekyll static site with nginx. I want the site served from a subdirectory in the url, e.g. <code>https://example.com/jekyll-site/</code>. The source files are in a git repo, cloned to the <code>/srv/website/html</code> folder on the server. When I run <code>jekyll build</code>, it creates the site's file in <code>/srv/website/html/_site</code>. There is an <code>index.html</code> file in <code>_site</code> that I want to use for an index directive. </p>
  
  <p>Here's the config I have so far:</p>
  
  <pre><code>server {
  
      # ...
  
      location / {
          # proxy_pass'es to another process
      }
  
      location = /jekyll-site {
          return 302 https://$host$request_uri/;
      }
  
      location /jekyll-site/ {
          root        /srv/website/html/_site;
          index       index.html;
          rewrite_log on;
          rewrite     /jekyll-site/(.*) /$1 break;
          try_files   $uri /index.html;
      }
  }
  </code></pre>
  
  <p>Now, if I point my browser at <code>https://example.com/jekyll-site/index.html</code>, then it serves the index file correctly. If I go to any post in the site, it gets served correctly. All of the internal links from one post to another work correctly. However, if I go to <code>https://example.com/jekyll-site/</code>, I get a <code>404</code> page, instead of the index page.</p>
  
  <p>What is wrong with my configuration? How do I configure nginx to serve the files from that folder, also with a correct <code>index</code> directive?</p>