ncr / rack-proxy

A request/response rewriting HTTP proxy. A Rack app.
MIT License
269 stars 94 forks source link

Can I use this gem to proxy a wordpress blog through heroku? #5

Closed dlupu closed 12 years ago

dlupu commented 13 years ago

Hy,

I'm looking for a solution that will allow me to keep my wordpress blog on www.example.com/blog after migrating to heroku. It seems that the only way to do this is to proxy the blog through the Rails application.

Is this possible with this gem? Thanks

ncr commented 13 years ago

It will work but won't scale ;)

2011/8/26 dlupu < reply@reply.github.com>

Hy,

I'm looking for a solution that will allow me to keep my wordpress blog on www.example.com/blog after migrating to heroku. It seems that the only way to do this is to proxy the blog through the Rails application.

Is this possible with this gem? Thanks

Reply to this email directly or view it on GitHub: https://github.com/ncr/rack-proxy/issues/5

Jacek Becela

http://trix.pl http://twitter.com/jacekbecela http://github.com/ncr

dlupu commented 13 years ago

That's not a problem. It's a low traffic blog for the time being.

Jacek, I haven't figured out how to use the gem yet. Could you please give me some guidelines on how I can use the gem to proxy all "/blog/*" uri's ?

Thanks

dlupu commented 13 years ago

Jacek,

I've managed to proxy the wordpress I was talking about. Everything works fine except cookies. I'm kinda stuck and i was wondering if there is any support in the gem for cookies?

BR D.

ncr commented 13 years ago

Hey,

Cookies should be forwarded automatically just like all other http request/response headers. Do you know at what point your cookies get lost?

dlupu commented 13 years ago

Jacek,

I haven't figured out that part yet. My guess is that I should do something different in rewrite_response or in my controller. Do you have any suggestions?

#config/routes.rb
match 'beta-blog' => "proxy#proxify"
match 'beta-blog*uri' => "proxy#proxify"

#lib/blog_proxy.rb
class BlogProxy < Rack::Proxy
   def rewrite_env(env)
        request.env["REQUEST_URI"].sub!("www.new-domain.com/beta-blog","old.domain.com")
        env["PATH_INFO"].sub!("/beta-blog","")
        env["PATH_INFO"] = "/" if env["PATH_INFO"].blank?
        env["SERVER_NAME"] = "old.domain.com"
        env["SERVER_PORT"] = 80
        env["HTTP_HOST"] = "old.domain.com"
        env
  end

  def rewrite_response(triplet)
    #status, headers, body = triplet
    triplet
  end
end

#app/controllers/proxy_controller.rb
class ProxyController < ApplicationController
  def proxify
     @result   = BlogProxy.new.call(request.env) 
     render :status => @result[0], :content_type => @result[1]["content-type"], :layout => false, :text => @result[2]
  end
end

Thanks! Dorian

ncr commented 13 years ago

I think the render method is missing the :headers param so it doesn't forward cookies to the client. Does that help?

tonydewan commented 13 years ago

I'm curious: why won't this scale? Is it an issue with rack-proxy, heroku, other?

I need this exact thing, but on a blog with more-than-tiny traffic.

ncr commented 13 years ago

It will scale if you can afford blocking one worker-process per request ;)

2011/10/1 Tony Dewan < reply@reply.github.com>

I'm curious: why won't this scale? Is it to with rack-proxy, heroku, other?

I need this exact thing, but on a blog with more-than-tiny traffic.

Reply to this email directly or view it on GitHub: https://github.com/ncr/rack-proxy/issues/5#issuecomment-2254676

Jacek Becela

http://trix.pl http://twitter.com/jacekbecela http://github.com/ncr

ncr commented 12 years ago

Closing this now, feel free to reopen if needed :)