Reverse Proxy with Trac


#1

Hi,

I have some trouble getting NGINX to work as a reverse proxy for one
or more Trac servers running in a separate virtual machine. I am new
to NGINX and I have been following the examples to get something
really basic up and running with one Trac instance. I am using the
Trac daemon tracd, which I have had up and running for some time now.
This is my nginx.conf

worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
include proxy.conf;
default_type application/octet-stream;

 sendfile        on;
 keepalive_timeout  65;

 server {
     listen       80;
     server_name  dev.mytestdom.dk;
     location /trac {
       proxy_pass http://192.168.0.187:8000/;
       proxy_redirect default;
     }
 }

}

The file “proxy.conf” is taken from
http://wiki.codemongers.com/NginxFullExample
and the mime.types comes with the distribution.

The problem is that it works with location “/” but not if I bind it to
“/trac” since the relative links in Trac are not translated correctly
i.e. I get links like “http://dev.mytestdom.dk/mypage” instead of
"http://dev.mytestdom.dk/trac/mypage
".

I tried both versions 0.7.19 and 0.6.32.

Any help is appreciated and I am really interested in using nginx as
reverse proxy for our many different servers.

Cheers
Mario


#2

On Thu, Oct 23, 2008 at 02:39:52PM +0200, Mario Gazzo wrote:

      proxy_pass http://192.168.0.187:8000/;

make this:


#3

On 23/10/2008, at 14.53, Almir K. wrote:

On Thu, Oct 23, 2008 at 02:39:52PM +0200, Mario Gazzo wrote:

     proxy_pass http://192.168.0.187:8000/;

make this:

     proxy_pass http://192.168.0.187:8000/trac;

Thanks for the reply but I did not explain myself very well. There is
no “/trac” subdirectory on the Trac server. The “/trac” subdirectory
is the path that I want to access trac with from the outside through
NGINX, which means the external URL becomes
"http://dev.mytestdom.dk/trac
". The internal trac url is still http://192.168.0.187:8000/ and when
it returns the page all relative links needs to be have “/trac”
prepended in order to work with the external address. E.g. The
internal address of a trac-page “http://192.168.0.187:8000/mypage
becomes “http://dev.mytestdom.dk/trac/mypage” when accessed from
outside.

I do not know how to do this with NGINX if at all but I know that this
is possible with another reverse proxy I tried but that I dumped for
various reasons.

Cheers
Mario


#4

Mario Gazzo wrote:

Thanks for the reply but I did not explain myself very well. There is
no “/trac” subdirectory on the Trac server. The “/trac” subdirectory
is the path that I want to access trac with from the outside through
NGINX, which means the external URL becomes
http://dev.mytestdom.dk/trac”. The internal trac url is still
http://192.168.0.187:8000/ and when it returns the page all relative
links needs to be have “/trac” prepended in order to work with the
external address. E.g. The internal address of a trac-page
http://192.168.0.187:8000/mypage” becomes
http://dev.mytestdom.dk/trac/mypage” when accessed from outside.
If I remember correctly, the relative links should work, but the
redirects would be giving you problems. In your trac.ini, if you set
the base_url parameter to the external url and then enable the
use_base_url_for_redirect setting it should handle this correctly (see
http://trac.edgewall.org/wiki/TracIni). I believe this is also needed
for the RSS feeds to work properly behind a proxy.


#5

Thanks for the tip. Seems that the base_url needs to be absolute in
order for this to work and I am not sure whether I would like to have
this in my trac.ini. I also found an alternative solution where the
new relative path is set inside Apache but this obviously requires
that Trac is run from Apache instead of the standalone Trac daemon.
This is not a problem for me since I will anyway be running other
stuff with Apache. The only problem with this solution is that in case
of a change I will have to change the path in multiple places (NGINX
and Apache conf).

I appreciate the support. Thanks a lot.

Cheers
Mario