# 500 Error when using proxy\_cookie\_domain

**URL:** <https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862>\
**Category:** NGINX\
**Created:** [May 18, 2012, 7:26pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862 "2012-05-18T19:26:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [May 18, 2012, 7:26pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/1 "2012-05-18T19:26:30Z")

</div>

Hello, I’m using Nginx as a reverse proxy and I’m seeing 500 errors  
anytime the proxy\_cookie\_domain option feature is used. I’m trying to  
change the domain in the “Set-Cookie” header.

The response header shows the replaced domain properly in the  
“Set-Cookie” header, however, it is a 500 Error response and does not  
output the page content.

Is there any way to find the cause of this error? I tried using both  
strace and the debug log, but could not find any cause.

Here is a snippet of the debug log

2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “User-Agent:  
curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b  
zlib/1.2.3 libidn/0.6.5”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Accept:  
_/_”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
"GET /test HTTP/1.0  
Host: [server.com](http://server.com)  
Connection: close  
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5  
OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5  
Accept: _/_

"  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http cleanup add: 09030628  
2012/05/18 13:16:10 [debug] 31932#0: \*1 get rr peer, try: 1  
2012/05/18 13:16:10 [debug] 31932#0: \*1 socket 12  
2012/05/18 13:16:10 [debug] 31932#0: \*1 epoll add connection: fd:12  
ev:80000005  
2012/05/18 13:16:10 [debug] 31932#0: \*1 connect to 194.71.107.15:80,  
fd:12 #2  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream connect: -2  
2012/05/18 13:16:10 [debug] 31932#0: \*1 posix\_memalign: 0902A140:128  
@16  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer add: 12:  
60000:1626601550  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http finalize request: -4,  
“/test” a:1, c:2  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http request count:2 blk:0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http run request: “/test”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream check client,  
write event:1, “/test”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream recv(): -1 (11:  
Resource temporarily unavailable)  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream request: “/test”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream send request  
handler  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream send request  
2012/05/18 13:16:10 [debug] 31932#0: \*1 chain writer buf fl:1 s:278  
2012/05/18 13:16:10 [debug] 31932#0: \*1 chain writer in: 09030644  
2012/05/18 13:16:10 [debug] 31932#0: \*1 writev: 278  
2012/05/18 13:16:10 [debug] 31932#0: \*1 chain writer out: 00000000  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer del: 12: 1626601550  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer add: 12:  
60000:1626601723  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream request: “/test”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http upstream process header  
2012/05/18 13:16:10 [debug] 31932#0: \*1 malloc: 09030A88:4096  
2012/05/18 13:16:10 [debug] 31932#0: \*1 recv: fd:12 2920 of 3979  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy status 200 “200 OK”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
“X-Powered-By: PHP/5.4.1”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Set-Cookie:  
PHPSESSID=055997276de6833c13c98c8707581925; path=/; [domain=.server.com](http://domain=.server.com)”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Set-Cookie:  
language=en\_EN; expires=Sat, 18-May-2013 17:16:10 GMT; path=/;  
[domain=.server.com](http://domain=.server.com)”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Set-Cookie:  
showArtist=1; expires=Thu, 13-May-2032 17:16:10 GMT”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Expires:  
Mon, 26 Jul 1997 05:00:00 GMT”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
“Last-Modified: Fri, 18 May 2012 17:16:10 GMT”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
“Cache-Control: no-store, no-cache, must-revalidate”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
“Cache-Control: post-check=0, pre-check=0”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Pragma:  
no-cache”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header:  
“Content-Type: text/html; charset=UTF-8”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Connection:  
close”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 posix\_memalign: 0907E4E0:4096  
@16  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Date: Fri,  
18 May 2012 17:16:10 GMT”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header: “Server:  
lighttpd”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http proxy header done  
2012/05/18 13:16:10 [debug] 31932#0: \*1 finalize http upstream request:  
500  
2012/05/18 13:16:10 [debug] 31932#0: \*1 finalize http proxy request  
2012/05/18 13:16:10 [debug] 31932#0: \*1 free rr peer 1 0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 close http upstream connection:  
12  
2012/05/18 13:16:10 [debug] 31932#0: \*1 free: 0902A140, unused: 88  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer del: 12: 1626601723  
2012/05/18 13:16:10 [debug] 31932#0: \*1 reusable connection: 0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http file cache free, fd: -1  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http finalize request: 500,  
“/test” a:1, c:1  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http special response: 500,  
“/test”  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http set discard body  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http subs filter header ignored,  
this may be special or compressed response  
2012/05/18 13:16:10 [debug] 31932#0: \*1 HTTP/1.1 500 Internal Server  
Error  
Server: nginx/1.3.0  
Date: Fri, 18 May 2012 17:16:10 GMT  
Content-Type: text/html  
Content-Length: 192  
Connection: close  
X-Powered-By: PHP/5.4.1  
Set-Cookie: PHPSESSID=055997276de6833c13c98c8707581925; path=/;  
[domain=.mydomain.com](http://domain=.mydomain.com)  
Set-Cookie: language=en\_EN; expires=Sat, 18-May-2013 17:16:10 GMT;  
path=/; [domain=.mydomain.com](http://domain=.mydomain.com)  
Set-Cookie: showArtist=1; expires=Thu, 13-May-2032 17:16:10 GMT

2012/05/18 13:16:10 [debug] 31932#0: \*1 write new buf t:1 f:0 0907E564,  
pos 0907E564, size: 436 file: 0, size: 0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http write filter: l:1 f:0  
s:436  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http write filter limit 0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 writev: 436  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http write filter 00000000  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http finalize request: 0,  
“/test” a:1, c:1  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer add: 11:  
5000:1626546906  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http lingering close handler  
2012/05/18 13:16:10 [debug] 31932#0: \*1 recv: fd:11 -1 of 4096  
2012/05/18 13:16:10 [debug] 31932#0: \*1 recv() not ready (11: Resource  
temporarily unavailable)  
2012/05/18 13:16:10 [debug] 31932#0: \*1 lingering read: -2  
2012/05/18 13:16:10 [debug] 31932#0: \*1 event timer: 11, old:  
1626546906, new: 1626546906  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http lingering close handler  
2012/05/18 13:16:10 [debug] 31932#0: \*1 recv: fd:11 0 of 4096  
2012/05/18 13:16:10 [debug] 31932#0: \*1 lingering read: 0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http request count:1 blk:0  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http close request  
2012/05/18 13:16:10 [debug] 31932#0: \*1 http log handler

Any help is appreciated!

Posted at Nginx Forum:

> **[500 Error when using proxy\_cookie\_domain](https://forum.nginx.org/read.php?2,226637,226637#msg-226637)**
>
> Hello, I'm using Nginx as a reverse proxy and I'm seeing 500 errors anytime the proxy\_cookie\_domain option feature is used. I'm trying to change the domain in the "Set-Cookie" header. The response header shows the replaced domain properly...

---

<div class="post-metadata">

**Author:** ![omar\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f4b2a3/32.png) [@omar\_h](https://www.ruby-forum.com/u/omar_h)\
**Post date:** [May 18, 2012, 7:30pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/2 "2012-05-18T19:30:51Z")

</div>

Also, this issue is occuring on both Nginx 1.3.0 and 1.2.0. I am using  
1 extra module, substitutions4nginx.

Posted at Nginx Forum:

> **[Re: 500 Error when using proxy\_cookie\_domain](https://forum.nginx.org/read.php?2,226637,226638#msg-226638)**
>
> Hello, I'm using Nginx as a reverse proxy and I'm seeing 500 errors anytime the proxy\_cookie\_domain option feature is used. I'm trying to change the domain in the "Set-Cookie" header. The response header shows the replaced domain properly...

---

<div class="post-metadata">

**Author:** ![omar\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f4b2a3/32.png) [@omar\_h](https://www.ruby-forum.com/u/omar_h)\
**Post date:** [May 18, 2012, 9:39pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/3 "2012-05-18T21:39:35Z")

</div>

On Friday 18 May 2012 21:25:41 omar\_h wrote:

> Here is a snippet of the debug log

[…]

Could you provide your config?

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![omar\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f4b2a3/32.png) [@omar\_h](https://www.ruby-forum.com/u/omar_h)\
**Post date:** [May 18, 2012, 10:01pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/4 "2012-05-18T22:01:53Z")

</div>

On Friday 18 May 2012 23:38:50 Valentin V. Bartenev wrote:

> > strace and the debug log, but could not find any cause.
> > 
> > Here is a snippet of the debug log
> 
> […]
> 
> Could you provide your config?

Never mind. I am able to reproduce the problem and going to fix it soon.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![omar\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f4b2a3/32.png) [@omar\_h](https://www.ruby-forum.com/u/omar_h)\
**Post date:** [May 18, 2012, 10:22pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/5 "2012-05-18T22:22:55Z")

</div>

On Friday 18 May 2012 21:25:41 omar\_h wrote:

> Here is a snippet of the debug log

The patch below should resolve this issue. Could you please test it?

# Index: src/http/ngx\_http\_upstream.c

— src/http/ngx\_http\_upstream.c (revision 4642)  
+++ src/http/ngx\_http\_upstream.c (working copy)  
@@ -3677,6 +3677,7 @@ static ngx\_int\_t  
ngx\_http\_upstream\_rewrite\_set\_cookie(ngx\_http\_request\_t \*r,  
ngx\_table\_elt\_t \*h,  
ngx\_uint\_t offset)  
{

- ngx\_int\_t rc;  
ngx\_table\_elt\_t \*ho;

- 

```
   return r->upstream->rewrite_cookie(r, ho);

```

- 

```
   rc = r->upstream->rewrite_cookie(r, ho);

```

- 

```
   return (rc == NGX_DECLINED) ? NGX_OK : rc;

```

}

return NGX\_OK;

---

<div class="post-metadata">

**Author:** ![omar\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f4b2a3/32.png) [@omar\_h](https://www.ruby-forum.com/u/omar_h)\
**Post date:** [May 18, 2012, 10:38pm UTC](https://www.ruby-forum.com/t/500-error-when-using-proxy-cookie-domain/219862/6 "2012-05-18T22:38:27Z")

</div>

The patch works!

Thank you very much.

Posted at Nginx Forum:

> **[Re: 500 Error when using proxy\_cookie\_domain](https://forum.nginx.org/read.php?2,226637,226646#msg-226646)**
>
> Hello, I'm using Nginx as a reverse proxy and I'm seeing 500 errors anytime the proxy\_cookie\_domain option feature is used. I'm trying to change the domain in the "Set-Cookie" header. The response header shows the replaced domain properly...
