6 messages in ru.sysoev.nginxRe: Nginx for proxy + rewrite
FromSent OnAttachments
Pavel GeorgievFeb 27, 2008 10:30 am 
Igor SysoevFeb 27, 2008 10:58 am 
Igor SysoevFeb 27, 2008 11:08 am 
Pavel GeorgievFeb 27, 2008 12:26 pm 
Igor SysoevFeb 27, 2008 12:42 pm 
Pavel GeorgievFeb 28, 2008 3:09 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Nginx for proxy + rewriteActions...
From:Igor Sysoev (is-G@public.gmane.org)
Date:Feb 27, 2008 12:42:14 pm
List:ru.sysoev.nginx

On Wed, Feb 27, 2008 at 10:27:18PM +0200, Pavel Georgiev wrote:

On Wednesday 27 February 2008 21:08:45 Igor Sysoev wrote:

On Wed, Feb 27, 2008 at 08:30:47PM +0200, Pavel Georgiev wrote:

I`ve beed using nxingx as a local balancer for few backend servers:

http { upstream mydomain.com { server 192.168.8.30; # backend server } server { listen 192.168.10.1:8080; server_name cmydomain.com;

location / { proxy_pass http://mydomain.com; proxy_redirect off; proxy_set_header Host $host; } } }

What I need to do is for a certain url to rewrite it to an external url but serve the requests as a proxy instead of returing a redirect, so this is transparent to the client:

http://mydomain.com/redirect/(.*)$ should go to http://extranal.comain.com/$1

I saw this is possible with a simple rewrite but it returns a redirect to the client. Is is possible to make nginx to server the rewrite as a proxy?

Or probably, you need X-Accel-Redirect:

http://wiki.codemongers.com/NginxXSendfile

What I`m trying to do is to server some location (/redirect/ in the example above) to an external server. It is doable with this:

location /redirect { rewrite ^/redirect/(.*)$ http://some.domain.com/$1 }

This however returns a 302 code, what I want is nginx to get the file requested from http://some.domain.com/ and server it to the client, so that the client doesn't have a clue that this was taken from an external server. In other words, I`d like to treat http://some.domain.com as a backend server, but just for a given location.

Hope that makes sense. I don't think X-Accel-Redirect is what I need here.

I still do not understand your problem. Probably, you need:

location / { proxy_pass http://mydomain.com; proxy_redirect off; proxy_set_header Host $host; }

location /redirect/ { proxy_pass http://some.domain.com/; }