nginx multiple domain virtual host configuration

Posted by Poe on Stack Overflow See other posts from Stack Overflow or by Poe
Published on 2010-05-22T18:49:05Z Indexed on 2010/05/22 18:50 UTC
Read the original article Hit count: 266

I'm setting up nginx with multiple domain or wildcard support for convenience sake, rather than setting up 50+ different sites-available/* files. Hopefully this is enough to show you what I'm trying to do. Some are static sites, some are dynamic with usually wordpress installed.

If an index.php exists, everything works as expected.

If a file is requested that does not exist (missing.html), a 500 error is given due to the rewrite. The logged error is:

*112 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/missing.html"

The basic nginx configuration I'm currently using is:

`

listen 80 default;
server _;

...

location / {
    root /var/www/$host;

    if (-f $request_filename) {
            expires max;
            break;
    }

    # problem, what if index.php does not exist?

    if (!-e $request_filename) {
            rewrite ^/(.*)$  /index.php/$1 last;
    }
}

...

`

If an index.php does not exist, and the file also does not exist, I would like it to error 404. Currently, nginx does not support multiple condition if's or nested if so I need a workaround.

© Stack Overflow or respective owner

Related posts about nginx

Related posts about http-status-code-404