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 wondering if it's possible to have a global error_page directive in nginx without redirecting (changing the URL in the browser's address bar).

I know this is possible by using a named location, but global error pages are declared in the http block, which doesn't allow location directives. I have a number of vhosts in my configuration and I'm trying to avoid adding this to current and all future vhosts.

I'm currently using nginx 1.3.0 if that makes a difference.

share|improve this question

1 Answer 1

error_page directive is exactly what you need. It can be used not only on 'location' level but also at 'server' or 'http' levels.

share|improve this answer
    
Thanks for the reply. error_page behaves differently when used in the http block than when used in a server or location block as it will do a full redirect to the error page URL. The only way to prevent this seems to be with the use of a named location, but you're not able to use location blocks inside the http block. Basically I'm attempting to set the error page globally for all vhosts on my server so that I don't have to explicitly set the error pages on all of them, cluttering up the configuration, but I don't want the browser to be redirected to the error_page URL. –  nuceman Jun 18 '12 at 19:01
1  
The only solution I've been able to come up with so far that's close to what I want has been to make a separate error.conf with the error page configuration and including it on all the vhosts. I'm assuming there is a way to do this with the error_page declarations in the http block but I have yet to come across a solution for it. –  nuceman Jun 18 '12 at 19:09
    
You are right with your workarroud, works fine. After some googling I found this post: serverfault.com/questions/381375/… Hope it helps someone –  atOm aNt Nov 18 at 0:10

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.