Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I want to direct the users to different web services with nginx configuration.

The scenario is for the internal users with host name from to I want to serve them some web service but for the other external visitor I don't want this to be realised.

I know I could use IP_TABLES to enable this feature, but I use IP_TABLE rules mainly for firewall purpose, I don't want to mix it with this configuration.

Is there any configuration available to me in the nginx.conf?

share|improve this question
What's your current configuration? Is it just a small subset of the resources in your site that you want to restrict? – Shane Madden Aug 24 '12 at 2:09
Yes, I want to restrict some scripts on the sites. – steveyang Aug 24 '12 at 9:23

You can use the GEO module together with a map directive:

http {
  geo $special_service {
    default 0; 1;
  server {
    if ($special_service) {
      return 302 $scheme://$server_name/special-service/;
share|improve this answer

Create a separate location block that covers your sensitive content.

Keep in mind that configuration directives don't inherit; you'll need to include in the new block anything that's in the existing `location that's needed for your content.

location /path/to/sensitive/stuff {
    # any other config that you need goes here..
    # ...
    deny all;
share|improve this answer

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.