Does anyone know of a method to use a different server root based on the remote host's IP? This fails with a "root not allowed here" message:

if ($remote_addr = myip) {
    root /some/other/root

The goal: serve files from a test directory to my static IP for development.

Unfortunately, I'm migrating a site to wordpress, so it needs to be set up with the correct port/hostname or else I'd simple set up a location /mytestdir {} block or separate server block with a port for testing. Wordpress is annoying in that if you set it up at mydomain.com:1234, it 's a lot of trouble to fix when you move it to mydomain.com (without a port).

I can set up a dev server as mydomain.com on my local network, but I would love to know how to do this in nginx on the same server.

  • I'm well aware of that process, though I'd still like to know about the nginx config. I'm generally use apache or lighttpd. Perhaps the process is greatly improved, but it used to be a royal pain migrating wp directories. I wish they'd just use things like src="/path/file" without the protocol/host. – thatthatisis Jan 21 '15 at 3:06

This question has been answered elsewhere. There seem to be 2 strategies:

  1. Using the nginx geo module. Nginx - How to redirect users with certain IP to special page

  2. Using a variable for the root dir. Nginx document root based on client ip?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.