Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically, I'm trying to handle nice URLs mapped to actual HTML files on the server.

I have URLs like so:


That need to return an HTML file on the filesystem like:


The location directive I have so far is:

location ^~ /(.*)/$ {
    alias /path/to/site/$1.html;

This sort of works, except only the following URL successfully resolves:

This URL (with trailing slash) returns a 404:

So I have two issues:

  1. How do I get the URL with trailing slash resolving correctly?
  2. More importantly, when nginx handles the alias, it doesn't appear to return any response headers. The HTML file is then downloaded as a file rather than being rendered to the browser.
share|improve this question

You need to change your regular expression, so it will handle both ways - with and without slash. Should be something like this I suppose:

location ^~ /(.*)/?$ {
    alias /path/to/site/$1.html;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.