Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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 http://ngxbot.lustfield.net/logs/%23nginx/2012/01/%23nginx.19.log 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.