Use Nginx to server different pages depending on IP address/subnet Announcing the arrival of...

Trademark violation for app?

Why is my ESD wriststrap failing with nitrile gloves on?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

What's the meaning of "fortified infraction restraint"?

Is there a kind of relay only consumes power when switching?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Putting class ranking in CV, but against dept guidelines

Do wooden building fires get hotter than 600°C?

AppleTVs create a chatty alternate WiFi network

Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?

What is the font for "b" letter?

Crossing US/Canada Border for less than 24 hours

How would a mousetrap for use in space work?

Project Euler #1 in C++

Sum letters are not two different

What does it mean that physics no longer uses mechanical models to describe phenomena?

Why is it faster to reheat something than it is to cook it?

Can an alien society believe that their star system is the universe?

How does light 'choose' between wave and particle behaviour?

Hangman Game with C++

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

Is there hard evidence that the grant peer review system performs significantly better than random?

What is the difference between globalisation and imperialism?



Use Nginx to server different pages depending on IP address/subnet



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Come Celebrate our 10 Year Anniversary!How to act differently according to the IP address with Nginx?How to set nginx root path based on hostThe downsides of using nginx as a primary web server?How to direct the visitor to certain http service according to their `host`?nginx : upstream with multiple server directives?Properly setting up a “default” nginx server for httpsnginx try_files index conflictModify HTML pages returned by nginx reverse proxyNGINX: different sites on the same domainNginX uses wrong config filenginx configuration for subdomain and proxy serverNginx Reverse Proxy Path on Parent Domain from Different Server





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







8















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 10.0.0.0/16) and another page to external users on any other IP address.



For example:




  • "Internal" PC with an IP of 10.0.0.34 goes to company.com/page.html gets page internal.html


  • "External" PC with an IP of 8.8.8.8 goes to company.com/page.html gets page external.html











share|improve this question




















  • 2





    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


















8















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 10.0.0.0/16) and another page to external users on any other IP address.



For example:




  • "Internal" PC with an IP of 10.0.0.34 goes to company.com/page.html gets page internal.html


  • "External" PC with an IP of 8.8.8.8 goes to company.com/page.html gets page external.html











share|improve this question




















  • 2





    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














8












8








8


2






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 10.0.0.0/16) and another page to external users on any other IP address.



For example:




  • "Internal" PC with an IP of 10.0.0.34 goes to company.com/page.html gets page internal.html


  • "External" PC with an IP of 8.8.8.8 goes to company.com/page.html gets page external.html











share|improve this question
















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 10.0.0.0/16) and another page to external users on any other IP address.



For example:




  • "Internal" PC with an IP of 10.0.0.34 goes to company.com/page.html gets page internal.html


  • "External" PC with an IP of 8.8.8.8 goes to company.com/page.html gets page external.html








nginx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 9 '11 at 12:14







Jon Rhoades

















asked May 9 '11 at 6:38









Jon RhoadesJon Rhoades

4,04822546




4,04822546








  • 2





    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














  • 2





    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








2




2





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





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










1 Answer
1






active

oldest

votes


















13














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;
10.0.0.0/8 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





















  • 2





    Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

    – Jon Rhoades
    May 12 '11 at 6:30














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f267611%2fuse-nginx-to-server-different-pages-depending-on-ip-address-subnet%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









13














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;
10.0.0.0/8 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





















  • 2





    Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

    – Jon Rhoades
    May 12 '11 at 6:30


















13














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;
10.0.0.0/8 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





















  • 2





    Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

    – Jon Rhoades
    May 12 '11 at 6:30
















13












13








13







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;
10.0.0.0/8 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















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;
10.0.0.0/8 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














share|improve this answer



share|improve this answer








edited 5 mins ago









Alex Volkov

1033




1033










answered May 9 '11 at 7:35









Alexander AzarovAlexander Azarov

3,1121519




3,1121519








  • 2





    Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

    – Jon Rhoades
    May 12 '11 at 6:30
















  • 2





    Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

    – Jon Rhoades
    May 12 '11 at 6:30










2




2





Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

– Jon Rhoades
May 12 '11 at 6:30







Worked nicely - I ended up doing location = /filename & rewrite ^ /filename.$client last;

– Jon Rhoades
May 12 '11 at 6:30




















draft saved

draft discarded




















































Thanks for contributing an answer to Server Fault!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f267611%2fuse-nginx-to-server-different-pages-depending-on-ip-address-subnet%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

117736 Шеррод Примітки | Див. також | Посилання | Навігаційне...

As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

Маріан Котлеба Зміст Життєпис | Політичні погляди |...