Welcome! Log In Create A New Profile

Advanced

Re: How to tell Proxy module to retrieve secondary URL if primary URL doenst exist

Maxim Dounin
October 05, 2012 08:34AM
Hello!

On Thu, Oct 04, 2012 at 12:08:55PM -0400, wurb32 wrote:

> Hi ,
>
> I tried with error_page and proxy_intercept_errors and it is not working for
> me. Do you mind if you can give me an example configuration?

Trivial config with fallback to a predefined static file would
look like:

location / {
error_page 404 = /fallback.jpg;

proxy_pass http://upstream;
proxy_intercept_errors on;
}

location = /fallback.jpg {
# serve static file
}

If you want rewrite from /something_300.jpg to /something_100.jpg
to happen automatically, for all possible values of "something",
then config like this should work, using named location and
rewrite:

location / {
error_page 404 = @fallback;

proxy_pass http://upstream;
proxy_intercept_errors on;
}

location @fallback {

# if request ends with _300.jpg - rewrite to _100.jpg
# and stop processing of rewrite rules, i.e. continue
# with proxy_pass; else return 404

rewrite ^(.*)_300.jpg$ $1_100.jpg break;
return 404;

proxy_pass http://upstream;
}

Documentation:

http://nginx.org/r/proxy_intercept_errors
http://nginx.org/r/error_page
http://nginx.org/r/location
http://nginx.org/r/rewrite

--
Maxim Dounin
http://nginx.com/support.html

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

How to tell Proxy module to retrieve secondary URL if primary URL doenst exist

wurb32 October 03, 2012 05:00PM

Re: How to tell Proxy module to retrieve secondary URL if primary URL doenst exist

Maxim Dounin October 04, 2012 05:46AM

Re: How to tell Proxy module to retrieve secondary URL if primary URL doenst exist

wurb32 October 04, 2012 12:08PM

Re: How to tell Proxy module to retrieve secondary URL if primary URL doenst exist

Maxim Dounin October 05, 2012 08:34AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 309
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