Forum: Ruby on Rails Set base url?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bart B. (Guest)
on 2006-03-06 18:08
(Received via mailing list)
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.
Gregory S. (Guest)
on 2006-03-06 18:39
(Received via mailing list)
On Mon, Mar 06, 2006 at 05:03:52PM +0100, Bart B. 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
Nicholas S. (Guest)
on 2006-03-06 23:29
(Received via mailing list)
On Mar 6, 2006, at 11:38 AM, Gregory S. 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'

Cheers,
Bart B. (Guest)
on 2006-03-07 07:03
(Received via mailing list)
Gregory S. wrote:

> } 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
Bart B. (Guest)
on 2006-03-07 10:20
(Received via mailing list)
Nicholas S. wrote:

> 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 B. (Guest)
on 2006-03-07 10:53
(Received via mailing list)
Bart B. wrote:

>>
>> 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
Gregory S. (Guest)
on 2006-03-07 15:06
(Received via mailing list)
On Tue, Mar 07, 2006 at 09:50:12AM +0100, Bart B. wrote:
} Bart B. wrote:
}
} > Nicholas S. wrote:
} >
} >> On Mar 6, 2006, at 11:38 AM, Gregory S. 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
Bart B. (Guest)
on 2006-03-07 17:08
(Received via mailing list)
Gregory S. wrote:

>
> 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
This topic is locked and can not be replied to.