Welcome! Log In Create A New Profile

Advanced

Re: error_page can not work in if directive

Maxim Dounin
December 25, 2012 12:26PM
Hello!

On Tue, Dec 25, 2012 at 11:47:58AM -0500, xinghua_hi wrote:

> thanks, but a new question comming。
> I try to resolve my problem according to your method:
> (1)
> “set" is also an location-level rewrite module directive, so the conf like
> this
> location / {
> root XXX;
> set $var "haha";
> error_page 413 /413.${var}.html;
> }
>
> will return 404, but 413.haha.html exists my root dir。I see the debug log ,
> find some log like
> http finalize request: 404, "/413..html?"
> obviously, nginx takes $var as an empty string, I think the reason is also
> that 413 error is generated before set directive? so , how to use variable
> in error_page uri?

Same problem here: the "set" directive isn't executed, and hence
the $var isn't "haha" but uninitialized and evaluates to an empty
string.

You have to make $var variable available by other means (e.g. set
the variable at server level, or make it available via map{}
directive).

> (2)
> if I writer conf like this:
> location / {
> set $var "haha";
> error_page 413 /413.html;
> }
>
> location = /413.html {
> if ($var) {
> rewriter ^ /413.new.html;
> }
> }
>
> the key problem is how can i pass the $var to location /413.html? I try
> it , the second $var is empty(I also wonder about the result because I
> remember when internal redirect, the location can share the variable) 。

And the same problem here: "set $var "haha";" in the location /
isn't executed, and hence $var remains uninitialized.

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

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

error_page can not work in if directive

xinghua_hi December 25, 2012 08:06AM

Re: error_page can not work in if directive

xinghua_hi December 25, 2012 09:36AM

Re: error_page can not work in if directive

Maxim Dounin December 25, 2012 09:44AM

Re: error_page can not work in if directive

xinghua_hi December 25, 2012 10:09AM

Re: error_page can not work in if directive

Maxim Dounin December 25, 2012 10:28AM

Re: error_page can not work in if directive

xinghua_hi December 25, 2012 11:47AM

Re: error_page can not work in if directive

Maxim Dounin December 25, 2012 12:26PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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