Forum: NGINX Need help with rewrite rule

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.
8072fdc83f765ae5075f252cb4d4d111?d=identicon&s=25 Chris Cortese (Guest)
on 2009-02-25 04:27
(Received via mailing list)
In Apache, I use the following rule.  It runs the combinator script,
which serializes, minimizes, and gzips a list of javascript files:

RewriteRule ^/javascript/(.*\.js) /combine.php?type=javascript&files=$1

In nginx, I've tried many things, to no avail.  Right now I have:

 rewrite ^/javascript/(.*\.js)$ /combine.php?type=javascript&files=$1
last;

When I load my page and expand the HTML in firebug, at the place where I
have:

<script type="text/javascript"
src="http://mysite.com/javascript/prototype.js,effects....

...it shows me 1 line as follows:

effects.js,builder.js,lightbox_live.js,box.js


Surely wildcards in nginx are greedy right?  Can anybody see what's
wrong here?


Thanks,
Chris
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-25 08:34
(Received via mailing list)
On Tue, Feb 24, 2009 at 07:15:09PM -0800, Chris Cortese wrote:

> have:
> wrong here?
nginx uses PCRE regex library:

$pcretest
PCRE version 7.6 2008-01-28

  re> #^/javascript/(.*\.js)$#
data>
/javascript/prototype.js,effects.js,builder.js,lightbox_live.js,box.js
 0:
/javascript/prototype.js,effects.js,builder.js,lightbox_live.js,box.js
 1: prototype.js,effects.js,builder.js,lightbox_live.js,box.js
data> ^D

BTW, I do not think that "the combinator script, which serializes,
minimizes, and gzips a list of javascript files" is a good thing.

It's much better to combine them statically.
8072fdc83f765ae5075f252cb4d4d111?d=identicon&s=25 Chris Cortese (Guest)
on 2009-02-25 09:00
(Received via mailing list)
So this should be working the same way it does on apache then.  $1 looks
correct from your test.  Is there anything else about nginx where it
would not like the comma?

Re: combine statically:  You mean just putting everything into one js
file?  If so, I guess that's one solution, but it makes for an extra
step whenever one js component gets updated.  Also, different parts of
the site may need different combinations of js files...  meaning more
work.  Before the combinator I was loading files individually, and the
combinator made some of my pages go from several seconds to ~ 1 second.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-25 09:12
(Received via mailing list)
On Tue, Feb 24, 2009 at 11:48:39PM -0800, Chris Cortese wrote:

> So this should be working the same way it does on apache then.  $1 looks
> correct from your test.  Is there anything else about nginx where it
> would not like the comma?

No, this should work.

> Re: combine statically:  You mean just putting everything into one js
> file?  If so, I guess that's one solution, but it makes for an extra
> step whenever one js component gets updated.  Also, different parts of
> the site may need different combinations of js files...  meaning more
> work.  Before the combinator I was loading files individually, and the
> combinator made some of my pages go from several seconds to ~ 1 second.

This on-fly combination is good for tens or hundreds requests per
second,
but on thousands it will be bottleneck.
Ed6583386f2b2d56e1b5eb2ee236da39?d=identicon&s=25 Nick Pearson (Guest)
on 2009-02-25 15:37
(Received via mailing list)
I use an on-the-fly asset compacting/concatenating script for my apps,
and
it works great.  The key is to cache the result so that it doesn't
become a
bottleneck, as Igor pointed out.  If you just store the file with the
URI
that was used to request it (commas and all), then this is as easy as
page
caching.

So, if a request comes in for:

    /javascript/prototype.js,effects.js,builder.js

just cache the file at something like:

    [root]/tmp/cache/prototype.js,effects.js,builder.js

and serve that cached file the way you would any normal, cached HTML
file
using either try_files or the "old" way of making sure the file exists
and
rewriting the request.
This topic is locked and can not be replied to.