# Proxy\_intercept\_errors and logging

**URL:** <https://www.ruby-forum.com/t/proxy-intercept-errors-and-logging/215728>\
**Category:** NGINX\
**Created:** [January 13, 2012, 8:47pm UTC](https://www.ruby-forum.com/t/proxy-intercept-errors-and-logging/215728 "2012-01-13T20:47:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 13, 2012, 8:47pm UTC](https://www.ruby-forum.com/t/proxy-intercept-errors-and-logging/215728/1 "2012-01-13T20:47:15Z")

</div>

Hi there,

We have nginx proxying to a bunch of django upstreams.

When those upstreams throw an error, we use proxy\_intercept\_errors to  
show a custom page. The problem is that this causes those 500s to be  
logged into the global access\_log, rather than the access\_log specified  
for that location. Here is a (reduced) example:

```
# at the server
access_log /logs/nginx/access.log accesslogformat;
proxy_intercept_errors on;
location ~ ^/oauth.*$ {
    proxy_pass http://appservers;

    access_log /logs/nginx/app.log applogformat;
}

```

Is there a way to get errors to log to the app.log in this case, even  
with proxy\_intercept\_errors to on? Right now we get all the 500s in the  
access.log.

Thanks in advance!  
Mike

Posted at Nginx Forum:

> **[proxy\_intercept\_errors and logging](https://forum.nginx.org/read.php?2,221201,221201#msg-221201)**
>
> Hi there, We have nginx proxying to a bunch of django upstreams. When those upstreams throw an error, we use proxy\_intercept\_errors to show a custom page. The problem is that this causes those 500s to be logged into the global access\_log, rather than...

---

<div class="post-metadata">

**Author:** ![mikeyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@mikeyk](https://www.ruby-forum.com/u/mikeyk)\
**Post date:** [January 13, 2012, 11:20pm UTC](https://www.ruby-forum.com/t/proxy-intercept-errors-and-logging/215728/2 "2012-01-13T23:20:51Z")

</div>

Hello!

On Fri, Jan 13, 2012 at 02:47:00PM -0500, mikeyk wrote:

> ```
> access_log /logs/nginx/access.log accesslogformat;
> proxy_intercept_errors on;
> location ~ ^/oauth.*$ {
> proxy_pass http://appservers;
> 
> access_log /logs/nginx/app.log applogformat;
> }
> 
> ```
> 
> Is there a way to get errors to log to the app.log in this case, even  
> with proxy\_intercept\_errors to on? Right now we get all the 500s in the  
> access.log.

Requests are logged in context of a location where their  
processing ends. This means that after error\_page redirection  
they will logged in the location where error\_pages are processed.

If you want them to be logged to the same app.log, you need to  
define location for errors with the same logging. To avoid mixing  
logs with normal errors, you may want to define separate  
error\_page’s for your apps. Something like this should work:

```
 location /oauth {
     proxy_pass ...

     proxy_intercept_errors on;
     error_page 502 504 /errors_oauth/5xx.html

     access_log /path/to/app.log applogformat;
 }

 location /errors_oauth/ {
     alias /path/to/errors/;
     access_log /path/to/app.log applogformat;
 }

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![mikeyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@mikeyk](https://www.ruby-forum.com/u/mikeyk)\
**Post date:** [January 14, 2012, 12:28am UTC](https://www.ruby-forum.com/t/proxy-intercept-errors-and-logging/215728/3 "2012-01-14T00:28:11Z")

</div>

Thanks so much for the response–this was exactly what we were looking  
for!

Posted at Nginx Forum:

> **[Re: proxy\_intercept\_errors and logging](https://forum.nginx.org/read.php?2,221201,221220#msg-221220)**
>
> Hi there, We have nginx proxying to a bunch of django upstreams. When those upstreams throw an error, we use proxy\_intercept\_errors to show a custom page. The problem is that this causes those 500s to be logged into the global access\_log, rather than...
