Rewrite Location header?

Hi.

Running nginx as a reverse proxy for trac. Reaching trac etc works, but
when posting login credentials, trac returns a Location: header as seen
below.

POST /somesite/login HTTP/1.1
Host: dev.somesite.co.za:8001
Referer: http://dev.somesite.co.za:8001/somesite/login
__FORM_TOKEN=ec42989d17edbcdec96290d6&referer=http%3A%2F%2Fdev.somesite.co.za%3A8001%2Fsomesite&user=user&password=pass

HTTP/1.x 303 See Other
Server: tracd/0.11.6 Python/2.5.2
Date: Wed, 03 Feb 2010 13:37:16 GMT
Location: http://dev.somesite.co.za:8001/somesite

This is the case when going through nginx too, but I now need to rewrite
the Location response header to http://ip_to_nginx:port/ instead, as the
trac server is not reachable from the outside.
Im kind of stuck :frowning:

Here’s the simple proxy_pass config:
location /somesite {
proxy_pass http://192.168.1.9:8001/somesite;
}

Posted at Nginx Forum:

On Wed, Feb 03, 2010 at 08:50:33AM -0500, 3molo wrote:

Server: tracd/0.11.6 Python/2.5.2
Date: Wed, 03 Feb 2010 13:37:16 GMT
Location: http://dev.somesite.co.za:8001/somesite

This is the case when going through nginx too, but I now need to rewrite the Location response header to http://ip_to_nginx:port/ instead, as the trac server is not reachable from the outside.
Im kind of stuck :frowning:

Here’s the simple proxy_pass config:
location /somesite {
proxy_pass http://192.168.1.9:8001/somesite;
}

You should add
proxy_redirect http://dev.somesite.co.za:8001/ /;


Igor S.
http://sysoev.ru/en/

I think I might put it in incorrect place;

  location /somesite {
  proxy_redirect http://dev.somesite.co.za:8001/ /;
  proxy_pass http://192.168.1.9:8001/somesite;
  }

Still the same Location header thou

Posted at Nginx Forum:

On Wed, Feb 03, 2010 at 09:41:30AM -0500, 3molo wrote:

my nginx is http://192.168.1.100:80 btw

Then you should set
server_name 192.168.1.100;

and remove proxy_redirect.


Igor S.
http://sysoev.ru/en/

Thanks alot for your help, Igor.

server_name already is 192.168.1.100;

Here’s my complete config:

user www-data www-data;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 8192;

events {
worker_connections 4096;
}

http {
include /etc/nginx/mime.types;

Proxy options

proxy_buffering on;
proxy_cache_min_uses 3;
proxy_cache_path /usr/local/nginx/proxy_temp/ levels=1:2
keys_zone=cache:10m inactive=10m max_size=1000M;
proxy_cache_valid any 10m;
proxy_ignore_client_abort off;
proxy_intercept_errors on;
proxy_next_upstream error timeout invalid_header;
proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;

default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status

'“$request” $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” “$http_x_forwarded_for”’;
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for
some vhosts

server {
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
index index.html;
listen 192.168.1.100:80 default;
root /usr/local/nginx/html;
server_name 192.168.1.100;

  # Proxy
  location /agilo {
    proxy_pass http://192.168.1.9:8001/;
  }

  location /svn {
    proxy_pass http://192.168.1.9/svn/;
  }
  location /somesite {
  proxy_pass http://192.168.1.9:8001/somesite;
  }
  }

}

Posted at Nginx Forum:

my nginx is http://192.168.1.100:80 btw

Posted at Nginx Forum:

Here’s the capture from the FF plugin Live HTTP headers, as you can see
it’s the same Location: redirect as when I post /somesite/login directly
to the “backend”.

http://192.168.1.100/somesite/login

POST /somesite/login HTTP/1.1
Host: 192.168.1.100
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.15)
Gecko/2009102815 Ubuntu/9.04 (jaunty) Firefox/3.0.15
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://192.168.1.100/somesite/login
Cookie: trac_form_token=8a237ed09a65182989b124f6;
trac_session=f3274da16804f3b8fbc786ea;
somesite_ZA_=6943021B818EE459F689B7CB2F203A8A3F0AD05F
Content-Type: application/x-www-form-urlencoded
Content-Length: 127
__FORM_TOKEN=8a237ed09a65182989b124f6&referer=http%3A%2F%2F192.168.1.100%2Fsomesite&user=user&password=pass


HTTP/1.x 303 See Other
Server: nginx/0.7.65
Date: Thu, 04 Feb 2010 06:24:20 GMT
Content-Type: text/plain
Connection: keep-alive
Location: http://dev.somesite.co.za:8001/somesite
Content-Length: 0
Pragma: no-cache
Cache-Control: no-cache
Expires: Fri, 01 Jan 1999 00:00:00 GMT
Set-Cookie: trac_auth=21e23f09d99de1381683a341118d37ad; Path=/somesite
Set-Cookie: trac_session=f3274da16804f3b8fbc786ea; expires=Thu,
04-Feb-2010 06:24:35 GMT; Path=/somesite

Posted at Nginx Forum: