ysbaddaden / prax

Rack proxy server for development
http://ysbaddaden.github.io/prax/
Other
475 stars 49 forks source link

https://mysite.dev returns error #116

Open BeerInHand opened 9 years ago

BeerInHand commented 9 years ago

Started prax with "prax start -f" - everything runs fine until I navigate into a secure section of the site that uses https and this error is returned:

E, [2015-03-07T14:19:52.802521 #3654] ERROR -- : ArgumentError: bad argument (expected URI object or URI string) /home/jimmy/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/uri/common.rb:998:in URI' /opt/prax/lib/prax/request.rb:136:indetermine_host' /opt/prax/lib/prax/request.rb:75:in host' /opt/prax/lib/prax/handler.rb:66:inapp_name' /opt/prax/lib/prax/handler.rb:17:in handle' /opt/prax/lib/prax.rb:21:inperform' /opt/prax/lib/prax/microworker.rb:84:in block in work' /opt/prax/lib/prax/microworker.rb:77:ineach' /opt/prax/lib/prax/microworker.rb:77:in work' /opt/prax/lib/prax/microworker.rb:63:inblock in spawn' I, [2015-03-07T14:19:52.802596 #3654] INFO -- : Respawning failed worker

This is on a fresh install of Ubuntu 14.04 LTS,. Is there some addition setup required to use ssl?

ysbaddaden commented 9 years ago

There shouldn't be more configuration required, as long as Prax is listening on :20558

You hit the dreadful bug that makes the host non determinable (prax can't proxy without a host to like the app to). Could you inspect the request sent from the browser? That would help debug.

BeerInHand commented 9 years ago

So I was wrong earlier when I said prax would serve no https requests - it does handle some https pages just fine. What I think is the issue is that the pages that error have a force_ssl = true. When it attempts to redirect to https is goes into an infinite redirect loop - as if it can't tell that the https protocol was already in use.

Here's the request headers:

Host: myapp.dev
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: _blink_direct_session=MWlMV3FDSkplankrTWdjK0pjRzBEbk1Pb0JONDlRVGdqUVQzWWlmSFg2TVhCQUN5Y2JOOUhVY0lPNENIYXhNWmZ0T1U5T0Y0T0hYNHZvblg1VHpQamNwNFNpdkNCZEtJNGZoTjVuZWl3SnZFMjJPclFadXpSc3dIcldCWmZxOURlV0lXTlg4MnhCUlhCbHViQlFHVDcvd1o0OXg4ZTBmdk5MMkNhcTVxQ3J1SnZJWFJ3Q2dGVnMvNkFjQXFIbTZxLS12WngzdHFaUXpLcXJwTEFmeDNxbmVBPT0%3D--a0b248ed1606ec27114097265266e5d19f9b8977; __ar_v4=%7CWJYR4PXKDZDSXEWSFWE664%3A20150307%3A1%7CDHI3RUCB4NBQ7D5DUR2KAF%3A20150307%3A1%7CPAA65RPUTFH6XFNGTPZF3I%3A20150307%3A1
Connection: keep-alive

Development Log:

Started GET "/login" for 127.0.0.1 at 2015-03-08 09:24:27 -0400
Processing by Blink::StoreFront::Users::LoginsController#new as HTML
  Parameters: {"protocol"=>"https"}
  MOPED: 127.0.0.1:27017 COMMAND      database=sgangster_development command={:count=>"blink_segments", :query=>{"deleted_at"=>nil}} runtime: 2.6091ms
Redirected to https://sgangster.dev/login
Filter chain halted as #<Proc:0x007f69a7e15e70@/home/jimmy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.1.9/lib/action_controller/metal/force_ssl.rb:65> rendered or redirected
Completed 301 Moved Permanently in 5ms

Started GET "/login" for 127.0.0.1 at 2015-03-08 09:24:27 -0400
Processing by Blink::StoreFront::Users::LoginsController#new as HTML
  Parameters: {"protocol"=>"https"}
  MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=>1} runtime: 0.3644ms
  MOPED: 127.0.0.1:27017 COMMAND      database=sgangster_development command={:count=>"blink_segments", :query=>{"deleted_at"=>nil}} runtime: 0.1572ms
Redirected to https://sgangster.dev/login
Filter chain halted as #<Proc:0x007f69a7e15e70@/home/jimmy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.1.9/lib/action_controller/metal/force_ssl.rb:65> rendered or redirected
Completed 301 Moved Permanently in 3ms

Started GET "/login" for 127.0.0.1 at 2015-03-08 09:24:27 -0400
Processing by Blink::StoreFront::Users::LoginsController#new as HTML
  Parameters: {"protocol"=>"https"}
  MOPED: 127.0.0.1:27017 COMMAND      database=sgangster_development command={:count=>"blink_segments", :query=>{"deleted_at"=>nil}} runtime: 3.5649ms
Redirected to https://sgangster.dev/login
Filter chain halted as #<Proc:0x007f69a7e15e70@/home/jimmy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/actionpack-4.1.9/lib/action_controller/metal/force_ssl.rb:65> rendered or redirected
Completed 301 Moved Permanently in 5ms

... repeated until browser gives up with "The page isn't redirecting properly" .

ysbaddaden commented 9 years ago

SSL never reaches the application itself. Prax will handle the HTTPS part and only tells the application about it with the X-Forwarded-Proto: https HTTP header. Maybe your application expects something else?

Prax must intercept/handle the HTTPS otherwise it wouldn't be able to know which application or port to proxy the request to.