Zoo/Rails redirects to port 80

Repository of web frameworks and applications for Microsoft IIS.
User avatar
Posts: 18
Joined: 30 May 2012, 23:43

Zoo/Rails redirects to port 80

13 Aug 2012, 05:22

I swear this didn't happen before, I even thought it was a problem of my new rails project I'm developing vs my old one, but now I've checked and it's happening with the old project to.

I'm running Zoo using thin as a backend. As I'm developing multiple sites I've kept them on different ports (easiest separation for now). However I've discovered that http://mysite:8080 works fine, right up until the rails controller triggers a redirect. (basically things like create/destroy, fairly common actions). This gets output in the rails log as

Code: Select all
Redirected to http://mysite/model/7


That's of course wrong, but it's the URL the browser gets, so it tries to find the nonexistant resource.

I'm a tad nooby with Zoo itself, is there a way to set it up to use subfolders?. Aka

http://mysite/railsapp1/model/7


That way it would at least be redirecting to the correct place. I've tried this in IIS 7 but I think I need to tell zoo that it's sitting inside a folder somehow, as it gets confused with the URLs if I set this up in IIS this way.

PS. I'll also mention this only happens when thin is launched via zoo. Booting up thin via console and using a random port works perfectly.

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Zoo/Rails redirects to port 80

13 Aug 2012, 07:29

Hello!

This is Rails application returning incorrect redirect location. I guess you need to specify the "current" location for the application somehow. It depends on the application in which way the current directory is set. I can finde something like:

Code: Select all
config.action_controller.relative_url_root = ENV[ 'APPL_VIRTUAL_PATH' ]


Sorry, I'm not much of Ruby programmer.

User avatar
Posts: 18
Joined: 30 May 2012, 23:43

Re: Zoo/Rails redirects to port 80

14 Aug 2012, 03:15

I'm not sure if this is rails related (specifically). It works fine on a linux box. It works fine if I launch thin manually. It seems more related to how Zoo is doing the reverse proxy.

Even specifying that environment variable to be the machine:port combo. It still redirects to port 80. :(

I didn't experience this behaviour with an older version of zoo. Though I'm not sure how I would even roll-back to test that.


Update:

So a workaround of sorts (at least to get rails apps actually usable in zoo again), is to host the app in a subfolder.

The best way i've seen of doing this, is to add RAILS_RELATIVE_URL_ROOT to the env variables
<environmentVariables>
<add name="RACK_ENV" value="production" />
<add name="RAILS_RELATIVE_URL_ROOT" value="/yourapp" />
</environmentVariables>


Then you need to wrap all your routes into a scope. A fairly non-intrusive way is like so (in your routes.rb)

App::Application.routes.draw do
scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
...your routes...
end
end


Bonus you can now easily host multiple rails apps on port 80.

If you want to host a rails app using the current version of zoo (on a non port 80 port), your out of luck. Zoo reverse proxies redirects to port 80 at the moment (which are fairly core to how rails operates)

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Zoo/Rails redirects to port 80

20 Aug 2012, 10:18

There was an error when PORT was not passed to the Rails engine as it expected. Please update your Helicon Zoo Module from the feed, it will fix port issue.

Also you may want to put this code into your web.config to support relative URLs


Code: Select all
<add name="RAILS_RELATIVE_URL_ROOT" value="%APPL_VIRTUAL_PATH%" />

User avatar
Posts: 18
Joined: 30 May 2012, 23:43

Re: Zoo/Rails redirects to port 80

21 Aug 2012, 06:13

Thanks for fixing it :)

Return to Helicon Zoo

Who is online

Users browsing this forum: No registered users and 5 guests