Reverse Proxy with Heroku (for WordPress) won’t show full pages

I am trying to use a reverse proxy to serve a WordPress blog running on EC2 at /blog from a rails app running on Heroku. I’ve used the rack-reverse-proxy gem and followed directions like this:

How can I use a subdirectory instead of a subdomain?

Read More

My app is running at http://myapp.com, my main target (wordpress) server is running at http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com.

The pages on the target server all serve up fine when accessed directly. However, no matter what page I try to get through the reverse proxy, the HTML gets cut off. I’ve tried serving via both my own custom builds of WordPress on Ubuntu (EC2) and on hosted examples like Bluehost. I’ve tried to access simple, handmade HTML and text test files, as well as the php files automatically generated by wordpress. Every time, the file is cut off.

  • Text files just get randomly cut off after ~1000 characters (this is variable)
  • Ditto for hand-coded HTML files
  • WordPress files seem to get cutoff during the <head> (often mid-word) and render an empty <body>.
  • If a page should exist (e.g. http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/test-post, it will load (at least partially) at myapp.com/blog/test-post, so I don’t know that rewrites are the issue.

I’ve tried enough variables on the wordpress/destination server that I’m inclined to think it’s something on the Rails side (I have the same issue whether running “myapp” locally or on a Heroku test server). Beyond that, I’m stuck.

Any thoughts as to what I might be doing wrong? There’s nothing in the Apache logs to indicate that anything is getting cut off. I’m pounding my head over this to no avail, and would really appreciate any help.

Related posts

Leave a Reply

2 comments

  1. FIXED IT!

    Digging into the rack-reverse-proxy gem, I found that I’m not the only person that had an issue with this:

    Seeing some issues with Content-Length being corrupted, this ensures it matches body length as delivered.

    The fix hasn’t been merged into the master branch, but I forked my own copy, applied the fix, and it’s working great. Hopefully it’ll be merged into the master and nobody else will have to worry about this.

    EDIT

    One more thing that might be helpful for somebody else, if they are having problems with Visual Editing Mode not working under wordpress: Make sure that you also include this update to have the headers get passed in properly. The gem just hasn’t really been updated in a couple of years, so it’s up to you to go through and copy in fixes from other people. Applying those two fixes has everything working fine for me with a Heroku app/AWS&Ubuntu WordPress setup.

  2. Heroku will cut the request after a certain amount of time which would cause the behavior that you’re seeing.

    You basically have to pull the page from the wordpress blog and reserve it via Rack in the time for one request – think that could be the problem?