Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

So i'v been trying out some of the config options in with no luck so far.

What I want is, if someone goes to '' that it loads the file '/webdir/page.php' (not to redirect them, but to keep them at '', but load the php page.

I don't really want to re-compile with since it isn't really what im after, I want to build my own custom directory index in php.

I had this working on Apache way back... but I'v long migrated to lightTPD and now i'v just moved to nginx :)

Any ideas?

share|improve this question

migrated from Jul 14 '10 at 13:47

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted
location /test/ {
  error_page 404 = /webdir/page.php;
  return 404;
share|improve this answer
I don't get 404 errors when I load a folder though, i get a 403, I changed it to 403 which does work... but I also block some users which also return 403 (if I am a blocked user) so I want to display a custom error to the blocked user as well, but not with PHP. – Mint Jul 15 '10 at 3:35
Hold on, nobody should be blocked. The error_page directive sets custom error page handler for /test/... only. "=" means drop the (404) status. return 404 triggers the handler. 403 should not pop up ever. What's your nginx version? – rzab Jul 15 '10 at 9:34
Oh I see, I interpreted it wrong. It works now, (with 404) but it still loads the page.php even when a proper page like test.html is selected. – Mint Jul 15 '10 at 11:49
You mean ? Ok, to load /webdir/page.php just for /test/, replace "location /test/" with "location = /test/". To match all the requests for directories (ending with /), "location ~ /$". If nginx hosts files all by itself (no proxying to apache), there're other ways to solve it. – rzab Jul 15 '10 at 15:36
So you must have "location /" declared then. Literal locations checked first, then regular expressions during lookup. A quick fix is to add error_page 403 = /webdir/page.php into "location /" – rzab Jul 16 '10 at 14:57

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.