5

I have setup a web server to view my repositories (a Gitalist instance) on http://localhost:3000 and I want to setup a proxy using nginx.

I want that the request is proxied to my repository view when receiving a URI like DOMAIN/git/.

My current nginx configuration has been declared as follows:

location /git {
    proxy_pass http://localhost:3000/;
}

The requests do get proxied to the server but none of the images/links or css can be resolved as they point to "http://localhost:3000/logo.png" for example.

EDIT

If I proxy_pass to the actual server address it does work:

 location /git {
        proxy_pass              http://192.168.1.111:3000/;
 }

But there should be a way of hiding the actual servers address while proxying.

5 Answers 5

2

In the case URIs are absolute, a solution could be using the Nginx HTTPSubModule or switching to Apache with its mod_proxy_html module. They are both able to modify the response received from backend servers and make some replacements.

1
  • 1
    Apache is a bad idea
    – deFreitas
    Jul 3, 2016 at 22:46
7

Try the solution presented in the nginx wiki:

http://wiki.nginx.org/LikeApache

the result, should be something like this.

location /git {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass              http://192.168.1.111:3000/;
}
0
0

The paths are not being proxied properly. See this link:

http://www.ubuntugeek.com/using-nginx-as-a-reverse-proxy-to-get-the-most-out-of-your-vps.html

1
  • I have read the article, and tried their proxy configuration but it isn't helping.
    – eliocs
    Mar 5, 2012 at 15:25
0

If an application produces HTML with absolute paths to graphics/scripts/pages and browser requests it -- neither application nor browser know you are trying to hide the application under /git path, so the browser will try to load them by their absolute paths. The whole idea would work if Nginx could re-write HTML, but it cannot.

0

If you're generating absolute links using the Host header sent in the request, then you should set Nginx to set that to the original Host header value, by adding:

proxy_set_header Host $http_host;

to the location block.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .