I have an application running on a Lighttpd instance which is proxied by an Apache server. It seems to work fine but my urls are incorrect: all urls reference / which is not where my application runs at the Apache server. How do I set the base url of a Rails application? My Apache has the following proxy rules: ProxyPass /hieraki http://localhost:3001 ProxyPassReverse /hieraki http://localhost:3001 But links in the Hieraki main page are like http://someserver.com/xml/rss for the RSS feed and http://someserver.com/wiki/folder/show/ROOT for the root.
On Mon, Mar 06, 2006 at 05:03:52PM +0100, Bart Braem wrote: } I have an application running on a Lighttpd instance which is proxied by an } Apache server. It seems to work fine but my urls are incorrect: all urls } reference / which is not where my application runs at the Apache server. } How do I set the base url of a Rails application? } } My Apache has the following proxy rules: } ProxyPass /hieraki http://localhost:3001 } ProxyPassReverse /hieraki http://localhost:3001 } But links in the Hieraki main page are like } http://someserver.com/xml/rss for the RSS feed } and http://someserver.com/wiki/folder/show/ROOT for the root. I just answered another question with similar information. See http://www.ruby-forum.com/topic/56927#43695 --Greg
On Mar 6, 2006, at 11:38 AM, Gregory Seidman wrote:> I just answered another question with similar information. See > http://www.ruby-forum.com/topic/56927#43695So you did... the correct answer is to use Rails'' relative_url_root. Although a config option for this setting is currently MIA, you can set it in your environment by doing ActionController::AbstractRequest.relative_url_root = ''/the/prefix/ rails/should/add/to/generated/links/and/remove/from/incoming/paths'' Cheers, -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060306/703bfe18/attachment-0001.html
Gregory Seidman wrote:> On Mon, Mar 06, 2006 at 05:03:52PM +0100, Bart Braem wrote: > } I have an application running on a Lighttpd instance which is proxied by > an } Apache server. It seems to work fine but my urls are incorrect: all > urls } reference / which is not where my application runs at the Apache > server. } How do I set the base url of a Rails application? > } > } My Apache has the following proxy rules: > } ProxyPass /hieraki http://localhost:3001 > } ProxyPassReverse /hieraki http://localhost:3001 > } But links in the Hieraki main page are like > } http://someserver.com/xml/rss for the RSS feed > } and http://someserver.com/wiki/folder/show/ROOT for the root. > > I just answered another question with similar information. See > http://www.ruby-forum.com/topic/56927#43695 >Seems like a good solution to me, thanks! I wonder if there are non-hack solutions, but this one works fine for me. Bart
Nicholas Seckar wrote:> On Mar 6, 2006, at 11:38 AM, Gregory Seidman wrote: > >> I just answered another question with similar information. See >> http://www.ruby-forum.com/topic/56927#43695 > > So you did... the correct answer is to use Rails'' relative_url_root. > Although a config option for this setting is currently MIA, you can > set it in your environment by doing > > ActionController::AbstractRequest.relative_url_root = ''/the/prefix/ > rails/should/add/to/generated/links/and/remove/from/incoming/paths'' >I tested this solution today and it does not work. I tried it on hieraki and I get urls like www.someserver.com/myurl/wiki/folder/show and when I click those I get Recognition failed for "der/show/ROOT" So the stripping does not seem to work?
Bart Braem wrote:> Nicholas Seckar wrote: > >> On Mar 6, 2006, at 11:38 AM, Gregory Seidman wrote: >> >>> I just answered another question with similar information. See >>> http://www.ruby-forum.com/topic/56927#43695 >> >> So you did... the correct answer is to use Rails'' relative_url_root. >> Although a config option for this setting is currently MIA, you can >> set it in your environment by doing >> >> ActionController::AbstractRequest.relative_url_root = ''/the/prefix/ >> rails/should/add/to/generated/links/and/remove/from/incoming/paths'' >> > I tested this solution today and it does not work. I tried it on hieraki > and I get urls like www.someserver.com/myurl/wiki/folder/show and when I > click those I get > Recognition failed for "der/show/ROOT" > So the stripping does not seem to work?Update: I discovered the problem (but no solution). I am running Apache as a proxy for a local Rails setup. So I proxy www.someserver.com/myurl to localhost:3000 and I ask Rails to append myurl. But Rails also strips myurl when receiving a request, even worse: it only strips the number of characters in myurl. In my case it was thiswiki so 8 characters, so www.someserver.com/myurl/wiki/folder/show/ROOT has www.someserver.com stripped off which results in myurl/wiki/folder/show/ROOT and then 8 characters are stripped off: der/show/ROOT. How should this be fixed? Did I do something wrong with the url_for method and should that work? Is this method completely wrong? I can''t be the only one in this situation, right? Thanks for your help Bart
On Tue, Mar 07, 2006 at 09:50:12AM +0100, Bart Braem wrote: } Bart Braem wrote: } } > Nicholas Seckar wrote: } > } >> On Mar 6, 2006, at 11:38 AM, Gregory Seidman wrote: } >> } >>> I just answered another question with similar information. See } >>> http://www.ruby-forum.com/topic/56927#43695 } >> } >> So you did... the correct answer is to use Rails'' relative_url_root. } >> Although a config option for this setting is currently MIA, you can } >> set it in your environment by doing } >> } >> ActionController::AbstractRequest.relative_url_root = ''/the/prefix/ } >> rails/should/add/to/generated/links/and/remove/from/incoming/paths'' } >> } > I tested this solution today and it does not work. I tried it on hieraki } > and I get urls like www.someserver.com/myurl/wiki/folder/show and when I } > click those I get } > Recognition failed for "der/show/ROOT" } > So the stripping does not seem to work? } } Update: I discovered the problem (but no solution). I am running Apache as a } proxy for a local Rails setup. So I proxy www.someserver.com/myurl to } localhost:3000 and I ask Rails to append myurl. } But Rails also strips myurl when receiving a request, even worse: it only } strips the number of characters in myurl. In my case it was thiswiki so 8 } characters, so www.someserver.com/myurl/wiki/folder/show/ROOT has } www.someserver.com stripped off which results in } myurl/wiki/folder/show/ROOT and then 8 characters are stripped off: } der/show/ROOT. } How should this be fixed? Did I do something wrong with the url_for method } and should that work? Is this method completely wrong? I can''t be the only } one in this situation, right? So now that I know the right way to do things, I can talk about how to make it work. Basically, you can''t use: ProxyPass /foo/bar http://localhost:3000/ ProxyPassReverse /foo/bar http://localhost:3000/ ...because it strips too much. Instead, you use: ProxyPass /foo/bar http://localhost:3000/foo/bar ProxyPassReverse /foo/bar http://localhost:3000/foo/bar Now Rails will strip and add exactly what it should. } Thanks for your help } Bart --Greg
Gregory Seidman wrote:> So now that I know the right way to do things, I can talk about how to > make it work. Basically, you can''t use: > > ProxyPass /foo/bar http://localhost:3000/ > ProxyPassReverse /foo/bar http://localhost:3000/ > > ...because it strips too much. Instead, you use: > > ProxyPass /foo/bar http://localhost:3000/foo/bar > ProxyPassReverse /foo/bar http://localhost:3000/foo/bar > > Now Rails will strip and add exactly what it should.When using this with ActionController::AbstractRequest.relative_url_root =''/foo/bar'' I can''t get my regular toy example to work because I get Recognition failed for "" With hieraki routing seems to work (why?) but the CSS and javascript fails. When surfing to the CSS or Javascripts I get messages like: Recognition failed for "/stylesheets/base.css" Recognition failed for "/javascripts/effects.js" What is going on here? Is the routing not working in Rails? Or is this use of Apache as a proxy so uncommon? Bart