Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 2 down vote accepted

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.

share|improve this answer

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

share|improve this answer
    
I have read the article, and tried their proxy configuration but it isn't helping. –  eliocs Mar 5 '12 at 15:25

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/;
}
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.