# Problem with proxies, redirections and headers

**URL:** <https://www.ruby-forum.com/t/problem-with-proxies-redirections-and-headers/223304>\
**Category:** NGINX\
**Created:** [September 28, 2012, 3:17pm UTC](https://www.ruby-forum.com/t/problem-with-proxies-redirections-and-headers/223304 "2012-09-28T15:17:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 28, 2012, 3:17pm UTC](https://www.ruby-forum.com/t/problem-with-proxies-redirections-and-headers/223304/1 "2012-09-28T15:17:17Z")

</div>

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  
[GitHub - rack/rack: A modular Ruby web server interface.](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](http://auth.ru)], nginx get the request  
and  
match #2, then it forwards to grack ([https://github.com/puzzle/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](http://auth.ru)

run lambda { |env|  
dir = Rack::Request.new(env).path\_info  
dir.slice!(0)  
dir = ‘/\_’ \<\< dir  
[200, {“Content-Type” =\> “.”, ‘X-Accel-Redirect’ =\> dir}, []]  
}
