error_page can not work in if directive

Maxim Dounin mdounin at mdounin.ru
Tue Dec 25 14:42:25 UTC 2012


Hello!

On Tue, Dec 25, 2012 at 08:06:45AM -0500, xinghua_hi wrote:

> I want to display different pages when 413 code return, for example
> 
> set $var 1;
> if ($var = 1) {
>      error_page 413 /413_old.html;
> }
> if ($var =2) {
>     error_page 413 /413_new.html;
> }
> 
>  error_page can not work, but I write error_page directive in location block
> directly instead of using if directive, it can work normally

There several ways to do what you want.  E.g. you may use 
variables in the error page specified, e.g.

   error_page 413 /413.$var.html;

or use an error_page with additional processing for the page in 
question, e.g.

   error_page 413 /413.html;

   location = /413.html {
       if ($new) {
           rewrite ^ /413.new.html;
       }
   }


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



More information about the nginx mailing list