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

For reasons to hideous to go into... I'm using Nginx as a webserver and would like it to serve one page for internal users (say on and another page to external users on any other IP address.

For example:

  • "Internal" PC with an IP of goes to gets page internal.html

  • "External" PC with an IP of goes to gets page external.html

share|improve this question
To clarify; Using Nginx isn't hideous, what I need it to do is! Nginx is great! – Jon Rhoades May 9 '11 at 12:41
up vote 12 down vote accepted

Make use of Nginx geo module. It lets you set variable's value based on a client IP address. geo directive must be in http section:

http {
  geo $client {
    default extra; intra;

You can use it later in locations to lookup files

location / {
  try_files $uri.$client $uri = 404;

Which means, Nginx will set $client to either extra or intra based on a client's IP. Let's assume it's a Intranet client. If a client asks for page.html, Nginx will search for file /your/root/page.html.intra. If there is no such file, it will search for /your/root/page.html. If it cannot find neither of these, Nginx returns 404 "Not Found" response. More on "try_files" in the documentation

By the way, index directive supports variables as well. E.g.

index index.$client.html index.html;
share|improve this answer
Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last; – Jon Rhoades May 12 '11 at 6:30

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.