Forum: NGINX Quick question

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.
mike (Guest)
on 2009-03-18 21:15
(Received via mailing list)
rewrites happen before location {} blocks are considered (if the
rewrite is on a global level) correct?

so

location /foo {
  this will never be computed
}

rewrite /foo/bar /somethingelse permanent;

That's at least what it seems to me, unless I'm missing something.

It doesn't seem like ^~ ~* etc seem to matter either. Or is it all
depending on the order in the config file?
Igor S. (Guest)
on 2009-03-18 21:21
(Received via mailing list)
On Wed, Mar 18, 2009 at 12:06:36PM -0700, mike wrote:

>
> That's at least what it seems to me, unless I'm missing something.
>
> It doesn't seem like ^~ ~* etc seem to matter either. Or is it all
> depending on the order in the config file?

Yes, as in Apache rewrites on server level run before location search.

Then (*) nginx chooses a location, then nginx runs rewrites inside
the location. If any rewrite is matched and it has not "break" flags,
then nginx chooses a location again, i.e, goes to (*).
This cycle may run no more than 10 times.
mike (Guest)
on 2009-03-18 21:40
(Received via mailing list)
well, i did it this way, and it seems to work...

rewrite ^/sites/foo/index.php$ http://foo.com/ permanent;
rewrite ^/sites/coolsw(|/)$ http://foo.com/ permanent;

# kill it from search engines
rewrite ^/sites/foo/(.*)$ /kill last;
location /kill {
        return 404;
}


2009/3/18 Igor S. <removed_email_address@domain.invalid>:
Igor S. (Guest)
on 2009-03-18 21:45
(Received via mailing list)
On Wed, Mar 18, 2009 at 12:33:15PM -0700, mike wrote:

> well, i did it this way, and it seems to work...
>
> rewrite ^/sites/foo/index.php$ http://foo.com/ permanent;
> rewrite ^/sites/coolsw(|/)$ http://foo.com/ permanent;
>
> # kill it from search engines
> rewrite ^/sites/foo/(.*)$ /kill last;
> location /kill {
>         return 404;
> }

However, it's better to runs these rewrites under

      location /sites/foo/ {
           rewrite  ^/sites/foo/index.php$ http://foo.com/ permanent;
           return   404;
      }

      location /sites/coolsw {
           rewrite  ^/sites/coolsw(|/)$ http://foo.com/ permanent;
      }
mike (Guest)
on 2009-03-18 21:56
(Received via mailing list)
2009/3/18 Igor S. <removed_email_address@domain.invalid>:

> However, it's better to runs these rewrites under
>
>      location /sites/foo/ {
>           rewrite  ^/sites/foo/index.php$ http://foo.com/ permanent;
>           return   404;
>      }
>
>      location /sites/coolsw {
>           rewrite  ^/sites/coolsw(|/)$ http://foo.com/ permanent;
>      }

ahh, duh. this works perfect. i had another rewrite i had missed that
was messing things up:

location /sites/foo {
        rewrite ^/sites/foo/index.php$ http://foo.com/permanent;
        rewrite ^/sites/foo(|/)$ http://foo.com/permanent;
        return 404;
}

Thanks!
This topic is locked and can not be replied to.