Serve different pages for different IP

I have one domain and I want to serve different pages based on the
Client
IP.

Nginx refuse different server with same server_name and both location
must
be / .

Can you help me?

Tnk

Posted at Nginx Forum:

On Tue, Dec 23, 2014 at 05:58:00AM -0500, magal wrote:

Hi there,

I have one domain and I want to serve different pages based on the Client
IP.

Nginx refuse different server with same server_name and both location must
be / .

Can you help me?

Set a variable based on the client IP ($remote_addr), using “geo” or
“map” or perhaps “if/set”.

Then, depending on what exactly you want to do, perhaps set “root” to
that variable value so that different clients see different parts of
the filesystem.

When I have had to do this before, I only handled the hard-coded first
request the clients made specially, and had the web server issue a
redirect to the client-specific url – so any client could access any
other client content if it asked for it directly, but the default was
that each client would get its own content after one extra http request.

f

Francis D. [email protected]

Thank you.

My configurations were:

root /path_to_root1;

if ($remote_addr = xx.xx.xx.xx) {

set $document_root /path_to root2;
}

map $remote_addr $document_root {

default /path_to_root1;

xx.xx.xx.xx /path_to root2;

}

geo $document_root {

default /path_to_root1;
xx.xx.xx.xx /path_to_root2;
}

I tryed the three ways you suggested but nginx always answered:

nginx: [emerg] the duplicate “document_root” variable.

My configuration would be to have one document_root for a specific IP
and
another for the rest of the world.

Did i make any mistake in my configuration?

thank you

Posted at Nginx Forum:

On Wed, Dec 24, 2014 at 10:16:28AM -0500, magal wrote:

Hi there,

My configuration would be to have one document_root for a specific IP and
another for the rest of the world.

In each case, do not set $document_root.

Instead, set $my_root_var (for example). Then separately, do

root $my_root_var;

f

Francis D. [email protected]