Gallery2 rewrite rules

Installed nginx for the first time, today, and like what I see!

Using spawn-fcgi from lighttpd, I now have nginx fronting my Gallery
2.2.4
site. Memory footprint is much smaller, and album load time is
noticeably faster.

That said, I’m struggling to convert the Apache mod_rewrite rules
generated by Gallery 2 into nginx equivalents.

Any takers on converting these?
http://www.donsbox.com/~dfelicia/g2_rewrites

I’m wondering if some of those are even needed.

You should see if gallery has a main file that can control the entire
app - like Wordpress, Drupal, etc. Then all you need is error_page 404
= /path/to/that/file.php?q=$request_uri; (or whatever the right
parameter is) - a lot of people for some reason think they need to set
wordpress specific rules for static files and wp-* files and the like;
but they don’t. Gallery could be the same way. It looks like it from
the top, but the bottom sets of rules I am not sure about.

Also - ditch spawn-fcgi. Use php-fpm :slight_smile:

Gallery2 does support PathInfo style routing.

I’m wondering if some of those are even needed.
They’re used by the rewrite module to allow “friendly” URLS. For
example:

This: http://pictures.donsbox.com/v/2008
Instead of: http://pictures.donsbox.com/main.php?g2_itemId=66556

You should see if gallery has a main file that can control the entire
app - like Wordpress, Drupal, etc.
The rewriting is only to produce human readable, friendly URLs. PHP
PathInfo is supported, too, so I can definitely do away with the
rewrites… but PathInfo is more expensive (and slower), so I was hoping
to convert the rewrite rules. Unfortunately, my regex prowess is
apparently not up to snuff, as I can’t make nginx happy.

Also - ditch spawn-fcgi. Use php-fpm :slight_smile:
I saw a blog, somewhere, recommending the same. I run Gentoo, though,
and
looks like it won’t be added:
http://bugs.gentoo.org/show_bug.cgi?id=208155 Guess I can patch the
ebuild, or compile vanilla sources + php-fpm, if there’s good reason.
What makes php-fpm superior? The doc is, umm, a bit light :slight_smile:
http://php-fpm.anight.org/docs.html

if you want i have written a ebuild that does the php-fpm patching and
copy’s php-fpm startup script / config files into place. If you want i
can
post it somewhere to let you download it. The only issue i had was you
can’t
have apache flag turned on because in the apache configure it never
generated the files needed to copy for start up etc. and apache is
always
done last.
I was also looking at trying to get clean Gallery2 urls and gave up as i
never could find resources or get them done correctly.

On Tue, Sep 16, 2008 at 5:10 PM, [email protected] wrote:

I’m wondering if some of those are even needed.
They’re used by the rewrite module to allow “friendly” URLS. For example:

Yes I know, but by default a lot of these apps put a lot of excess
rewrite URLs that aren’t really needed.

The rewriting is only to produce human readable, friendly URLs. PHP
PathInfo is supported, too, so I can definitely do away with the
rewrites… but PathInfo is more expensive (and slower), so I was hoping
to convert the rewrite rules. Unfortunately, my regex prowess is
apparently not up to snuff, as I can’t make nginx happy.

Pathinfo shouldn’t be that bad. I use pathinfo stuff all over and it’s
never been the bottleneck as far as I can tell. :slight_smile:

What makes php-fpm superior? The doc is, umm, a bit light :slight_smile:
http://php-fpm.anight.org/docs.html

It matures fastcgi inside of PHP, makes it much easier and centrally
controlled to start PHP engines without needing some custom script to
launch a bunch of spawn-fcgi commands; spawn-fcgi has not worked
properly for me in the past (are you sure it’s -really- rotating your
processes at PHP_FCGI_MAX_REQUESTS? mine wasn’t), php-fpm includes
better process termination/request timeouts, per-pool php.ini
overrides (although php 5.3 will help a lot with that) and works well
in conjunction with nginx… it’s too difficult to name them all. I
evaluated a lot of options for PHP engines + adaptive spawning +
ability to run as a user (suexec-ish style) and PHP-FPM meets all of
those (except for adaptive spawning which is one of last remaining
things for it to be feature complete. it’s already planned and plumbed
for it)

here’s my build script. includes suhosin too.
Thanks, Mike.

if you want i have written a ebuild that does the php-fpm patching and
copy’s php-fpm startup script / config files into place.
Can you post? Thanks!

here’s my build script. includes suhosin too.

#!/bin/bash
VER=5.2.6
BD=pwd
rm -rf php-${VER}
wget -c http://us3.php.net/get/php-${VER}.tar.gz/from/this/mirror
tar xvfz php-${VER}.tar.gz
cd php-${VER}
cp …/php-5.2.6-fpm-0.5.8.diff .
patch -p1 < php-5.2.6-fpm-0.5.8.diff
cp …/suhosin-patch-${VER}.patch .
patch -p1 < suhosin-patch-${VER}.patch
./configure
–enable-fastcgi
–enable-discard-path
–enable-force-cgi-redirect
–enable-fpm
–with-fpm-pid=/var/run/php-fpm.pid
–with-fpm-log=/var/log/php-fpm.log
–with-fpm-conf=/etc/php-fpm.conf
–enable-cli
–enable-inline-optimization
–disable-rpath
–disable-ipv6
–enable-mbstring
–enable-mbregex
–enable-sqlite-utf8
–with-mysql
–with-mysqli=/usr/bin/mysql_config
–with-curl
–with-zlib
–with-gd
–with-jpeg-dir=/usr
–with-png-dir=/usr
–with-freetype-dir
–enable-gd-native-ttf
–enable-exif
–enable-shmop
–with-xsl=shared
–with-mssql=shared
–enable-soap=shared
–enable-sockets
–enable-pcntl=shared
–with-mcrypt
–with-bz2
–with-tidy
–with-pcre-dir
–with-openssl
–with-imap=shared
–with-imap-ssl
–with-kerberos
–with-pear
make -j2
make install
cd $BD
rm -rf php-${VER}

On Tuesday of September 16 2008, [email protected] wrote:

That said, I’m struggling to convert the Apache mod_rewrite rules
generated by Gallery 2 into nginx equivalents.

A bit late but may be useful (instead of pathinfo approach) - I used sth
like
this:

location /v/
{
if ($request_uri !~ /main.php)
{
rewrite ^/v/(.*)$ /main.php?g2_view=core.ShowItem&g2_path=$1
last;
}
}

location /d/
{

if ($request_uri !~ /main.php)
{

rewrite /d/(\d+)-(\d+)/([^/?]+)
/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3
last;
}

}

regards