# 301 Redirects Break Long Posts?

**URL:** <https://www.ruby-forum.com/t/301-redirects-break-long-posts/215764>\
**Category:** NGINX\
**Created:** [January 15, 2012, 3:49am UTC](https://www.ruby-forum.com/t/301-redirects-break-long-posts/215764 "2012-01-15T03:49:09Z")\
**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 15, 2012, 3:49am UTC](https://www.ruby-forum.com/t/301-redirects-break-long-posts/215764/1 "2012-01-15T03:49:09Z")

</div>

Hello,

I’m running nginx 1.0.10 with a few name based virtual hosts configured.  
There are a few permanent redirects configured of the format:

```
server {
    listen 80;
    server_name domain.com;
    rewrite ^/(.*) http://www.domain.com/$1 permanent;
}

```

The site sees frequent POSTs to it, which in turn seemingly randomly  
disconnect from the upstream server after sending the data along (the  
request completes successfully upstream and then complains of a broken  
pipe  
as nginx has disconnected). The disconnects seem highly coupled to 301  
redirects - in the debug logs it appears that every POST is interrupted  
by  
a permanent redirect (and that the thread serving the request stops  
serving  
requests entirely after the redirect finishes, the last debug statement  
being “http log handler”). After removing the server block the POSTs  
run  
without any problems. I’m wondering if this is enough information to  
arouse anyone’s suspicions as to what the problem is? Any help would be  
greatly appreciated.

-Harish

---

<div class="post-metadata">

**Author:** ![Harish\_Agarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3ab097/32.png) [@Harish\_Agarwal](https://www.ruby-forum.com/u/Harish_Agarwal)\
**Post date:** [January 15, 2012, 4:01am UTC](https://www.ruby-forum.com/t/301-redirects-break-long-posts/215764/2 "2012-01-15T04:01:28Z")

</div>

On 15 Jan 2012 02h48 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> server\_name [domain.com](http://domain.com);  
> rewrite ^/(.\*) [http://www.domain.com/$1](http://www.domain.com/$1) permanent;  
> }

To do that type of thing try this and see of it helps:

server {  
listen 80;  
server\_name [domain.com](http://domain.com);  
return 301 http://www.domain.com$request\_uri;  
}

There’s no need for any regex capture or rewrite for that matter. The  
$request\_uri variable has both the uri and the query string.

> anyone’s suspicions as to what the problem is? Any help would be  
> greatly appreciated.

— appa

---

<div class="post-metadata">

**Author:** ![Harish\_Agarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3ab097/32.png) [@Harish\_Agarwal](https://www.ruby-forum.com/u/Harish_Agarwal)\
**Post date:** [January 15, 2012, 4:13am UTC](https://www.ruby-forum.com/t/301-redirects-break-long-posts/215764/3 "2012-01-15T04:13:47Z")

</div>

Hi Antonio,

Thanks for the tip! I was serving 301s in this way before and was still  
experiencing the problem mentioned. I’ll revert the configuration for  
now  
but any other advice would be great!

Thanks,  
-Harish
