Limit to IP, redirect all others to alternate site?

Phillip Oldham phill at
Tue Mar 30 13:36:37 MSD 2010

How would I limit a virtual host to a single IP and redirect all other 
IPs to an alternate domain/website? I'm using the http_access module to 
limit IPs which returns a 403, but I'd prefer that nginx return a 
"location" header to bounce visitors to

At the moment I've got this:

server {
     if ( $remote_addr != ) {
         rewrite ^ last;

     location / {
         deny all;

but that feels quite "hacky". Is there a better format?

More information about the nginx mailing list