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 see this question was also asked here: Configure Nginx global error page but there wasn't a suitable answer.

I am currently allowing only certain IPs to some of my sites and would like Nginx to drop connections from the rest of the IPs instead of returning a 403. Ideally, I would like to do this without configuring each site separately.

I have this in the http section:

error_page 403 =444;

But, now, it tries to serve up the page =444 instead of returning a 444.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

So you can do a few things

error_page   403  http://example.com/forbidden.html;

Or you can do something like

error_page 403 /403.html

location /403.html {
    root /some/path/that/has/file; 
}

for the 403.html would be in /some/path/that/has/file

share|improve this answer
    
I would have to add that location block to all of my server blocks, correct? I'm trying to avoid having to edit every one of the server blocks since there are so many. Thanks! –  sidprak Apr 10 '12 at 20:42
    
if you do the location {} option yes.. if you do the one above it that can go in the http {} but I believe it redirects. –  Mike Apr 10 '12 at 20:48
    
Ok, makes sense; thanks for the explanation. I can't get the second option to work, though. For some reason, Nginx tries to look for /some/path/that/has/file/403.html/index.html and then fails since 403.html is not a directory. Any suggestions? –  sidprak Apr 10 '12 at 20:50
    
edit your post and show that part of the config –  Mike Apr 10 '12 at 22:23
    
I just did more research and, originally I was trying to return a blank page to achieve the result, but I found I can return a 444. Now my question becomes, how do I return a 444 when an IP address is denied? –  sidprak Apr 10 '12 at 22:38

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.