August 18, 2010 09:44PM
Hi,
On 18/08/2010 22:31, hendrik wrote:
> Hi everyone,
>
> I am using nginx as a proxy for custom URLs. I call URLs like
> /proxy/www.example.com/favicon.ico and nginx acts as a proxy for
> www.example.com/favicon.ico. This works fine as long as the response
> from the upstream server is not a 301. If it is a 301, this gets
> forwarded to the client which then calls the target location directly.
>
> Is there a way nginx can resolve these 301s and deliver the contents to
> the client? You can find the config below.
I think you should be able to do this by compiling the headers-more
module (http://github.com/agentzh/headers-more-nginx-module) and have a
config like :

proxy.conf
--------------

resolver 8.8.8.8;
proxy_pass http://$1;
more_set_headers -s '301 302 303' 'Location: /proxy/$upstream_http_location'; # you might want to add more 30x's here


nginx.conf
-------------
location ~ ^/proxy/http://(.*)$ {

include proxy.conf;

}

location ~ ^/proxy/(.*)$ {

include proxy.conf;

}

though I've not tested it. I think that $upstream_http_location will be
set after the response from the source server, but I'm not certain.

A few notes :

- Having a proxy without some kind of security check is probably not a
good idea. You could do this with your proxy, but could also be done
with iptables.
- There's probably not much point in trying to enforce 'domain/url' in
the regex. It will slow things down, and you don't really gain
anything. Same with case-insensitive regexes.
- Nginx buffers responses until the request has been completed before
passing to the client. On small files, this shouldn't be a problem, but
on big ones it might. On continual audio/video streams, it will block
(as far as I know, and it did the last time I tested it).
- Depending on what you're using it for, you might be better off using
Apache Trafficserver as a high-performance forward proxy. The
performance is good, and I think it'll be able to do what you want, but
the config files are really ugly.

Cheers,

Marcus.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx as a proxy, needs to follow 301 responses

hendrik August 18, 2010 05:31PM

Re: Nginx as a proxy, needs to follow 301 responses

Eugaia August 18, 2010 09:44PM

Re: Nginx as a proxy, needs to follow 301 responses

hendrik August 20, 2010 11:25AM

Re: Nginx as a proxy, needs to follow 301 responses

Eugaia August 20, 2010 01:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 267
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready