title: Rewrite root address to a subdirectory in nginx
body: <p>I'm converting my mediawiki site to use nginx as a frontend for static files with apache on the backend for php. I've gotten everything working so far except for when I view the root directory "example.com" it tries to serve a directory listing and gives a 403 error since I have that disabled and don't have an index file there.</p>
  
  <p>The apache rewrite rule I have in place right now is simply:</p>
  
  <pre><code>RewriteRule ^$ /wiki/Main_Page [L]
  </code></pre>
  
  <p>I tried something similar with a location directive in nginx, but it's not working:</p>
  
  <pre><code>location = / {
      rewrite "^$" /wiki/Main_Page;
  }
  </code></pre>
  
  <p>The rest of my location directives are:</p>
  
  <pre><code>location / {
      try_files $uri $uri/ @rewrite;
  }
  
  location @rewrite {
      rewrite ^/wiki/(.*)$ /w/index.php?title=$1&amp;$args;
  }
  
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      try_files $uri /w/index.php?title=$1&amp;$args;
      expires max;
      log_not_found off;
  }
  
  location ~ \.php?$ {
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $host;
      proxy_pass http://127.0.0.1:8080;
  }
  </code></pre>
  
  <p>I can simply put an index.php file with header('Location:') in it, but I'd rather just do it properly with a rewrite rule.</p>
  
  <p>All the examples I've found online for running mediawiki with nginx run the wiki as wiki.example.com instead of a /wiki/ subdirectory.</p>
  
  <p>Edit: I also tried adding to the try_files like this: <code>try_files $uri $uri/ @rewrite /wiki/Main_Page;</code> with the same 403 error result.</p>