Forum: NGINX nginx bug

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Victor I. (Guest)
on 2009-04-21 01:19
Ok, there has to be a bug here some where. My $request_uri isn't
matching.

I have also ran if ($request_uri !~ "^/resources/.*") {} just to see if
my regexp is messed up. The line isn't being evaluated.
I am pretty sure it is reaching the proxy_pass since I can add
"add_header X-Foo 'bar';" and that will be appended to response.

nginx 0.7.52

location / {
            if ($request_uri ~ "^/resources/.*") {
                add_header X-Foo 'bar';
                expires 30d;
            }

            if (!-f $request_filename) {
                proxy_pass http://127.0.0.1:8089;
                break;
            }
}

Is there url
curl -I
http://mydomain.com/resources/org.apache.wicket.Ap...
Maxim D. (Guest)
on 2009-04-21 03:12
(Received via mailing list)
Hello!

On Mon, Apr 20, 2009 at 11:19:55PM +0200, Victor I. wrote:

> location / {
>             if ($request_uri ~ "^/resources/.*") {
>                 add_header X-Foo 'bar';
>                 expires 30d;
>             }
>
>             if (!-f $request_filename) {
>                 proxy_pass http://127.0.0.1:8089;
>                 break;
>             }
> }

I'm not really sure that I understand what you are trying to say,
but it looks like there is some misunderstanding how 'if' directive
works.

Unless used with rewrite module directives (e.g. set) 'if'
directive will create "hidden" location that will work as normal
one if rewrite module processing stops in it (i.e. break directive
used).  It doesn't really influence request processing if rewrite
module processing doesn't stop there.

Since you have no 'break' in your "if ($request_uri ...)" -
add_header and expires directives there doesn't matter.

It's somewhat ugly and one of the reasons why usage of 'if' is
generally discouraged.

Instead, you should rewrite your configuration to something like
this:

    location / {
        try_files $uri @proxy;
    }

    location @proxy {
        proxy_pass http://127.0.0.1:8089;
    }

    location /resources/ {
        try_files $uri @proxy_resources;
        add_header X-Foo 'bar';
        expires 30d;
    }

    location @proxy_resources {
        proxy_pass http://127.0.0.1:8089;
        add_header X-Foo 'bar';
        expires 30d;
    }

Maxim D.
Victor I. (Guest)
on 2009-04-21 04:11
Maxim D. thank you so much! You just saved me from pulling out my
hair.

            if ($request_uri ~ "^/resources/.*") {
                expires 30d;
                proxy_pass http://127.0.0.1:8089;
                break;
            }

Works perfectly. I did not know things get discarded in if statements. I
would ideally be using try_files but I have varnish in front of nginx to
cache data. There are some issues with nginx on solaris using /dev/poll,
connections in rapid succession get dropped and eventports just stops
responding after a few hours of medium amount of traffic.
This topic is locked and can not be replied to.