Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

The scenario is for the internal users with host name from 192.168.1.1 to 192.168.1.255 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. –  yangchenyun Aug 24 '12 at 9:23
add comment

2 Answers

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

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

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..
    # ...
    allow 192.168.1.0/24;
    deny all;
}
share|improve this answer
add comment

Your Answer

 
discard

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.