Rhodecode behind Apache Proxy in Subdirectory

549 views
Skip to first unread message

evilazrael

unread,
Feb 12, 2011, 1:46:42 PM2/12/11
to rhodecode
Hi Guys,

looks like this is general Pylons problem, but here's how to get it
work with rhodecode.
For example you have a few apps you want to get working with ssl on
the same port with an apache reverse proxy then you need to use
subdirectories. Rhodecode shall be made available under https://server/rhodecode.

Step 1: Add prefix to rhodecode.
Edit your Pylons ini file for Rhodecode. In [app:main] make sure
static_files is set to true and add
filter-with = proxy-prefix
Add the following at the end of the file
[filter:proxy-prefix]
use = egg:PasteDeploy#prefix
prefix = /rhodecode

This makes the rhodecode app available at root and /rhodecode.

Step 2: Setup Apache.
Set in the general setup or in the appropiate VirtualHost the
following
<Location /rhodecode>
ProxyPass http://127.0.0.1:59542/rhodecode
ProxyPassReverse http://127.0.0.1:59542/rhodecode
SetEnvIf X-Url-Scheme https HTTPS=1
</Location>

59542 is my port for rhodecode and the SetEnvIF line is saying
rhodecode to stay with https. Remove it if you use http.

If you start now both, you will have the problem that Rhodecode
generate the wrong absolute paths for CSS, images and Javascript: /
images, /css/ resp. /js. It looks like there is no way to make them
dynamically. If you don't want to make redirections for that stuff or
copy them into the root of apache, you have to change this paths in
the sources :(

Step 3: Modify sources
Go to the directory where rhodecode is installed (probably the egg
directory in site-packages). Issue the following commands:
find . \( -name "*.html" -o -name "*.js" -o -name "*.css" \) |xargs -n
1 sed -i 's/\"\/images\//\"\/rhodecode\/images\//g'
find . \( -name "*.html" -o -name "*.js" -o -name "*.css" \) |xargs -n
1 sed -i 's/\"\/css\//\"\/rhodecode\/css\//g'
find . \( -name "*.html" -o -name "*.js" -o -name "*.css" \) |xargs -n
1 sed -i 's/\"\/js\//\"\/rhodecode\/js\//g'
This will add /rhodecode/ to the beginning of all "/images/" "/css/" "/
js/" paths.

Now start both servers. You have now cleanly separated Rhodecode into
its own directory.

For me this is only a temporary solution as you probably will have to
repeat Step 3 after every update of Rhodecode.

Please give me a feedback if that worked for you.

evilazrael

unread,
Feb 12, 2011, 1:52:25 PM2/12/11
to rhodecode
Each of the commands in step 3 consists of 2 lines.

Alpar Juttner

unread,
Feb 13, 2011, 12:59:46 AM2/13/11
to rhod...@googlegroups.com
Hi,

Many thanks for the answer, the proposed code replacement indeed works,
though it looks quite a dirty hacking for me.

Just for curiosity, where does the problem lie?
Does Pylons make relocation completely impossible (which case - being
Pylons a generic web framework - would be rather strange) or it is just
rhodecode which is not prepared to do it?

Regards,
Alpar

evilazrael

unread,
Feb 13, 2011, 7:56:42 AM2/13/11
to rhodecode
Hi,

> Many thanks for the answer, the proposed code replacement indeed works,
> though it looks quite a dirty hacking for me.

It is a quick & dirty hack.

> Just for curiosity, where does the problem lie?
> Does Pylons make relocation completely impossible (which case - being
> Pylons a generic web framework - would be rather strange) or it is just
> rhodecode which is not prepared to do it?

This is the first pylons application i installed. and it looks like
other pylons project suffer from the same problem. My proposal is not
to serve these file statically, but to serve them through a small
script which replaces some placeholder variables like {$URL_PREFIX}
or so. On modern machines the impact should be neglectable. With that
you could place images on different web server in arbitary
directories, for example on the proxying apache and not necessary in
the general images.
I prefer to keep stuff together in one directory. Image you have two
pylons applications and each one wants to use the /image/ directory..

marcinkuzminski

unread,
Feb 13, 2011, 8:04:32 AM2/13/11
to rhodecode

Hi, i see no problem in puting a configurable prefix for statoc files
in rhodecode
if this would be usefull i can extrend rhodecode to have this

Alpar Juttner

unread,
Feb 13, 2011, 10:15:57 AM2/13/11
to rhod...@googlegroups.com
On Sun, 2011-02-13 at 05:04 -0800, marcinkuzminski wrote:
> Hi, i see no problem in puting a configurable prefix for statoc files
> in rhodecode
> if this would be usefull i can extrend rhodecode to have this

It would be _very_ useful, indeed.

Currently, the only safe way to use RhodeCode through SSL along with
other services on a server is to acquire a separate IP address dedicated
to RhodeCode.

Regards,
Alpar

marcinkuzminski

unread,
Feb 15, 2011, 1:14:10 PM2/15/11
to rhodecode
In latest tip version of rhodecode (https://rhodecode.org/rhodecode) i
replaced all calls to static files
from eg. /images/file.png into url("/images/file.png") that's the same
function that generates urls for rhodecode,
So I believe that after that change the static files will also append
the prefix in the same manner as it does in generation of regular
urls.

Anyone care to test this ?
(remember that You need tip VCS library to run rhodecode 1.2)

https://rhodecode.org/rhodecode
https://rhodecode.org/vcs

marcinkuzminski

unread,
Feb 15, 2011, 1:17:41 PM2/15/11
to rhodecode
Additionally it can be achieved with such regex for /css, /images and /
js in current release

("\/images\/.+?") replace to "\${h\.url($1)}"

On Feb 15, 7:14 pm, marcinkuzminski <marcin...@gmail.com> wrote:
> In latest tip version of rhodecode (https://rhodecode.org/rhodecode) i
> replaced all calls to static files
> from eg. /images/file.png into url("/images/file.png") that's the same
> function that generates urls for rhodecode,
> So I believe that after that change the static files will also append
> the prefix in the same manner as it does in generation of regular
> urls.
>
> Anyone care to test this ?
> (remember that You need tip VCS library to run rhodecode 1.2)
>
> https://rhodecode.org/rhodecodehttps://rhodecode.org/vcs

Alpar Juttner

unread,
Feb 17, 2011, 9:01:43 AM2/17/11
to rhod...@googlegroups.com
Hi,

> In latest tip version of rhodecode (https://rhodecode.org/rhodecode) i
> replaced all calls to static files
> from eg. /images/file.png into url("/images/file.png") that's the same
> function that generates urls for rhodecode,

Thanks for fixing this issue.

> On Tue, 2011-02-15 at 10:17 -0800, marcinkuzminski wrote:
> Additionally it can be achieved with such regex for /css, /images and /
> js in current release
>
> ("\/images\/.+?") replace to "\${h\.url($1)}"

Does release 1.1.3 already contain this? Or should we change it
manually?

Alpar

P.S. I really love the responsiveness of RhodeCode development to the
user requests and ideas.

marcinkuzminski

unread,
Feb 17, 2011, 9:14:37 AM2/17/11
to rhodecode
RhodeCode 1.1.3 does contain this fix.
I actually considered this fix a very high priority and it was easy to
fix.
So it's been merged into the bugfix release.


Regards
Marcin Kuzminski
Reply all
Reply to author
Forward
0 new messages