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

I'm trying to make

/ -> /foo/index.html
/(about|people|contact) -> /foo/(about|people|contact).html
/blah.(jpg|css|js) -> /foo/blah.(jpg|css|js)

but also

/index.html -> 404
/(about|people|contact).html -> 404
* -> 404

So far I have:

  # Serve our home page.
  location / {
    root /foo/;

  location = / {
    alias /foo/;

  location ~ /(about|people|contact) {
    default_type text/html;
    alias /foo/$1.html;

  location ~ /(.+\.(jpg|css|js)) {
    root /foo/;

While this exposes the files I want exposed via the non-.html URLs, it doesn't 404 any files.

Thanks in advance for any help.

share|improve this question

The problem is that the very first thing I had tried (not mentioned in my question),

location = / { alias /foo/index.html; }

results in

"/var/www/intro/index.htmlindex.html" is not a directory

In my question above, I changed this to something that at least could serve the page, plus a useless line that conveyed my intention:

location / { root /foo/; }
location = / { alias /foo/; } # seems to be ignored

From I found that you can replace the second line with:

location = / { root /foo/; rewrite ^ /index.html break; }

Then make location / point somewhere else, e.g. an empty directory:

location / { root /var/www/; }

Not sure this is the most elegant solution, but it seems to work.

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.