Forum: NGINX Problem with proxies, redirections and headers

Posted by Gautier DI FOLCO (Guest)
on 2012-09-28 15:17
(Received via mailing list)
Hi all,

I have to set up an infrastructure that allows the dynamic management of 
SCM
repositories (svn/git, creation/destruction, authentication via MySQL,
clone/checkout, pull/update, push/commit).

This is the way a query that I wanted to set up: nginx receives a 
request,
#1 matches, request goes to daemon authentication (I use Rack
https://github.com/rack/rack/), it ask for an username and a
password (Basic Auth), check the permissions and send the url to execute 
and
to return to the client via X-Accel-redirect (yet it does nothing but
redirect)
[configuration is below and is called auth.ru], nginx get the request 
and
match #2, then it forwards to grack (https://github.com/puzzle/grack/) 
and
will treat all back to the client. Currently my authtification system 
works
well (i.e. it redirects to the correct url), the daemon grack, when 
accessed
directly, handles correctly the requests of Git clients, but when I try 
to
give
them via nginx, the Content-type header returned to the client is
text/plain,
this is not those returned by grack. Here's my setup, I made a mistake 
but
I do
not see why.
Do you have any idea?


For your help,
In advance,
Thanks.

# nginx.conf
    location ~ /(svn|git)/(.*)$ { #1
      proxy_pass         http://127.0.0.1:8000/$1/$2;
      proxy_redirect     off;

      proxy_set_header   Host                $host;
      proxy_set_header   X-Real-IP           $remote_addr;
      proxy_set_header   X-Forwarded-For     $proxy_add_x_forwarded_for;

      proxy_set_header   X-Sendfile-Type     X-Accel-Redirect;

    }

    location ~ /_git/(.*) { #2
      internal;
      proxy_pass         http://127.0.0.1:8001/$1;
      proxy_redirect     off;

      proxy_set_header   Host                $host;
      proxy_set_header   X-Real-IP           $remote_addr;
      proxy_set_header   X-Forwarded-For     $proxy_add_x_forwarded_for;

    }

# auth.ru
run lambda { |env|
    dir = Rack::Request.new(env).path_info
    dir.slice!(0)
    dir = '/_' << dir
    [200, {"Content-Type" => ".", 'X-Accel-Redirect' => dir}, []]
}
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.