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'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
add comment

2 Answers

up vote 0 down vote accepted
$server_addr

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
add comment

If you're using an SSH tunnel, it's likely that your traffic to nginx will be coming from 127.0.0.1, 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 127.0.0.1) –  nickgrim Nov 15 '12 at 20:09
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.