nginx rewrite rules for Gallery 2 (RC1) and Gallery 1.

viulian

Joined: 2008-08-26
Posts: 4
Posted: Tue, 2008-08-26 04:37

Here are the nginx rewrite rules that work for me.

For gallery2 (they include G1 -> G2 URL Mapping redirects).

nginx.conf:

                location /gallery/ {
                        index index.php;
                        if (!-e $request_filename) {
                                rewrite ^/gallery/d/([0-9]+)-([0-9]+)/([^\?]+)$ /gallery/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g
2_fileName=$3 last;
                                rewrite ^/gallery/v/([^\?]+)$ /gallery/main.php?g2_path=$1 last;
                                rewrite ^/gallery/([^\?]+)$ /gallery/main.php?g2_controller=migrate.Redirect&g2_path=$1;
                        }
                }

You must have URL Rewrite activated. When you activate it in G2, the "global + follow symlinks" has to be marked as working (followed by Save) even if the tests do not work yet at the moment you activate it.
Also, because I don't know how gallery2 works internally, I kept on the "G1->G2 URL Rewrite Rule" on (I mean I don't know if this does more than adding an entry to the .htaccess file). In particular, the G1->G2 rewrite rule is included in the list above (it's the last line) so even if you later deactivate it from "Site Admin", please remember to also remove it from the nginx.conf file (and then issue a reload of the configs).

I haven't yet tested remote uploads, I've read in the migration documents that I might need to remove gallery2_remote.php or something. Will try and post an update.

The story is that I do not want apache on my VPS. I've successfully migrated a G1 to G2 RC1 (I wanted piclens/cooliris support from the newest slideshow plugin and it works!, than you gallery2 programmers) but it took a while to convert the apache rewrite rules to nginx.
Hopefully they will be useful for someone else too, or maybe support for nginx will be added in Gallery 2.

For gallery 1, the rewrite rules I used successfully are below:

                location /gallery/ {
                        index index.php;
                        if (!-d $request_filename) {
                                rewrite ^/gallery/([^\.\?/]+)/([0-9]+)$ /gallery1/view_photo.php?set_albumName=$1&index=$2 last;
                                rewrite ^/gallery/([^\.\?/]+)/([A-Za-z_0-9\-]+)$ /gallery/view_photo.php?set_albumName=$1&id=$2 last;
                                rewrite ^/gallery/([^\.\?/]+)/$ /gallery/$1 last;
                                rewrite ^/gallery/([^\.\?/]+)$ /gallery/view_album.php?set_albumName=$1 last;
                        }
                }

Good luck :)

 
dfelicia

Joined: 2007-08-07
Posts: 9
Posted: Sat, 2008-09-13 00:26

Hey, thanks for posting this. I've started using nginx + php at work, and am considering making the switch for my gallery, too. Have you done any performance comparison? My gallery gets very little traffic... it's just for family and friends, so I'm mainly interested in reducing my g2 memory footprint (free some memory on my VPS for other stuff), and (possibly) single user performance improvement.

Are you using memchached module in nginx?

I'd be interested in your seeing your entire nginx.conf, if you feel like posting it.

 
viulian

Joined: 2008-08-26
Posts: 4
Posted: Sat, 2008-09-13 04:43

Hello and thank you for the kind words.

I've been using nginx for the past year, my nginx.conf is rather big (I host several domains with it); it is big and don't know if it's really helpful.
Here are the answers to your question:
a) I did not do any performance tests. When I first moved to nginx I also moved to a new VPS, so everything was already working better. Then as I moved gallery1 to gallery2, I was really after piclens/cooliris support and not the perfomance; the overall feeling is that is moving faster than gallery1. This again might be code optimizations in g2 compared to g1. However, my VPS memory footprint is under 180Mb with Mysql having 200Mb databases (in total) and a cumulative of about 100.000 page views per month on my domains. So it's ok - I have a 386Mb of RAM VPS, and for these I think I would have needed at least 786Mb VPS for apache equivalent (I also gave up sendmail and replaced by qmail + patches, BIND is replaced by djbdns including zone transfers to easydns.net, gave up openssh to go with dropbear, etc).
In conclusion: half the price of VPS hosting at the at least the same speed as apache/sendmail/bind.
b) No, I do not use memcached. As I'm satisfied with the speed so far, I preferred to let me have some options when site usages might increase :) But I use the nginx_stats module, and the graphs are pretty nice.

I run nginx with 3 (or 4, forgot exactly how many) FASTCGI children, which are set to be killed and respawned after they handled 10000 calls. I'm amazed in the quality of work put into nginx and Dan Bernstein's tools, there are absolutely no memory leaks in the past 8 months or so. The average even dropped a few Mb (from 184Mb to 174Mb) after switching from g1 to g2.

For speed, you can check: http://hex.ro/gallery , it's the one hosted with g2 on nginx.

 
dfelicia

Joined: 2007-08-07
Posts: 9
Posted: Sat, 2008-09-13 18:49

Your gallery is fast. You've convinced me. I'm going to give it a whirl.

BTW, I totally agree w/you about DJB's software. I, too, run qmail, daemontools, and djbdns. Rock solid (and secure)!

 
mikeage
mikeage's picture

Joined: 2005-01-23
Posts: 138
Posted: Sun, 2008-10-12 15:41

I'm trying to migrate to nginx, but I'm having some trouble with the rewrite rules. Can you confirm that the rules above work with G2.2?

Also, do you need to do some form of QSA in nginx rewrites? How does it know to append the query string (if there was one)?

Thanks

 
justinj1

Joined: 2005-11-21
Posts: 67
Posted: Wed, 2009-09-30 11:10

Having trouble with these rules also, in particular for the modules like add comment/view comments and rss

Anyone have working rules for those features? I tried the ones here http://www.evilcoder.org/2009/06/21/gallery2-to-gallery3/

but no luck :)

 
viulian

Joined: 2008-08-26
Posts: 4
Posted: Wed, 2009-09-30 19:25

I didn't even know that g3 is rolling... I think I have to include Gallery2 on the same list of software as nginx, install once and forget about it.

I will give it a chance in the following week and if I can get the rules, I will happily post them here.