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

I'm writing a generic config script for a site and want to block all traffic to a certain url except the traffic from the server itself because I want to allow only SSH tunneled trafic to access that part of the site.

location /admin {
    allow SERVERIP; 
    deny all;

Has nginx a variable I can use for this so I don't have to add it manually for every server I use the config with.

share|improve this question
up vote 0 down vote accepted

The server address. Generally nginx makes a system call to obtain this value. To improve efficiency and avoid this system call, specify an address with the listen directive and to use the bind parameter.

Documented here.

share|improve this answer

If you're using an SSH tunnel, it's likely that your traffic to nginx will be coming from, so just allow that.

share|improve this answer
I thought so but for some reason I can't get the config working with localhost or the serverip. – Stofke Nov 14 '12 at 22:06
Just tried localhost and it seems to work as you suggested unfortunately $server_addr is more or less what I asked for so I rewarded that answer although I'm sure using localhost is more effecient as it doesn't need the extra lookup. – Stofke Nov 14 '12 at 22:12
Note that if you've got IPv6 enabled on the box that localhost will sometimes resolve (first) to ::1 which might cause issues for servers that are only listening on IPv4 (and why I explicitly suggested – nickgrim Nov 15 '12 at 20:09

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.