Try_files and redirect loops

Hi all!

I need to make sure try_files does not send to a static file if $args
are included.

 #if ($args != "") {rewrite ^ @ app;} # tried here and below.

 location = / { rewrite ^ /home/index/$host; }
 location / {
   if ($args = "") { rewrite ^ @app;}
   try_files /downtime.html $uri/index.html $uri @app;# double

rewrite error
}

 location @app {
   proxy_pass http://app_server;
   ...

I also tried something like this, but “break” makes it not match the
location @app either.

Thanks for any help you can give me, my forehead is sore from pounding
it against the keyboard :slight_smile:
-Kevin

 location / {
   # reload=auto refreshes cached content.  hmm, easy to have this

match twice which causes problems!
if ($http_cache_control ~* “no-cache”) { rewrite ^ $uri?recache;
}
if ($args != “”) {rewrite ^ @app;}

   location = / { rewrite ^ /home/index/$host; }
   location ~* /$ { rewrite ^ $uri/index.html; }

   # after break won't match any location rules either :(
   if (!-f $uri) {rewrite ^ @app; break;}
 }

 location @app {
   proxy_pass http://app_server;

Posted at Nginx Forum:

On Mon, Apr 18, 2011 at 11:37:06AM -0400, inspire22 wrote:

Hi there,

I need to make sure try_files does not send to a static file if $args
are included.

So… what do you want to happen if $args are included?

I’ll guess “check for /downtime.html, then try the app server”. In which
case, the following might be close:

===
server {
set $u1 $uri/index.html;
set $u2 $uri;
if ($is_args) {
set $u1 “”;
set $u2 “”;
}

try_files /downtime.html $u1 $u2 @app;

location @app {
proxy_pass http://app_server;
}
}

You’ll need some extra bits, for example to define app_server, but it
might give some inspiration.

Good luck with it,

f

Francis D. [email protected]

Clever, thanks! Working pretty well :slight_smile: Is there any way to print a
variable to the error log so I can debug some more-complicated logic
with setting things?

How on earth can try_files be more efficient than a specific if-list?
Doesn’t it have to stat more files?

Posted at Nginx Forum:

On Mon, Apr 18, 2011 at 01:50:27PM -0400, inspire22 wrote:

Hi there,

Clever, thanks! Working pretty well :slight_smile:

Good stuff.

Is there any way to print a
variable to the error log so I can debug some more-complicated logic
with setting things?

I’ve usually been able to find what I needed in the debug log.

If you’re going to try setting and logic in the config file, you’ll want
to make sure that you understand how things are processed. Especially
“if” inside “location”.

Check the wiki and mail archives for more.

Good luck with it,

f

Francis D. [email protected]