FAQ

Page Discussion History

Difference between revisions of "ZenPhoto"

(new nginx configuration for zenphoto.)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
[http://www.zenphoto.org/ ZenPhoto Gallery] needs a few rewrite rules, I was lucky to find that Matt Martz had done all the hard work already. (See below for more comprehensive rewrite rules which also cover news and pages)
+
In the Gallery Admin page set:
 
+
<pre>
+
location / {
+
index index.php;
+
 
+
rewrite ^/admin/?$ /zp-core/admin.php redirect;
+
 
+
if (-d $request_filename) {
+
rewrite ^/albums/?(.+/?)?$  /$1  redirect;
+
}
+
 
+
if (-e $request_filename) {
+
break;
+
}
+
 
+
rewrite index\.php$  /index.php  last;
+
rewrite ^/page/([0-9]+)/?$  /index.php?page=$1  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/?$  /index.php?p=$1  last;
+
rewrite ^/(.*)/page/([0-9]+)/?$  /index.php?album=$1&page=$2  last;
+
rewrite ^/(.*)page/([A-Za-z0-9\-_]+)/?$  /index.php?album=$1&p=$2  last;
+
 
+
rewrite ^/page/([A-Za-z0-9\-_]+)/fields([0-9]+)/(.*)/([0-9]+)/?$  /index.php?p=$1&searchfields=$2&words=$3&page=$4  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/fields([0-9]+)/(.*)/?$  /index.php?p=$1&searchfields=$2&words=$3  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/archive/(.*)/([0-9]+)/?$ /index.php?p=$1&date=$2&page=$3  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/archive/(.*)/?$  /index.php?p=$1&date=$2  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/tags/(.*)/([0-9]+)/?$  /index.php?p=$1&searchfields=4&words=$2&page=$3  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/tags/(.*)/?$  /index.php?p=$1&searchfields=4&words=$2  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/(.*)/([0-9]+)/?$ /index.php?p=$1&words=$2&page=$3  last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/(.*)/?$  /index.php?p=$1&words=$2  last;
+
 
+
rewrite "^/(.*)/image/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2  last;
+
rewrite ^/(.*)/image/([^/\\\]+)$  /zp-core/i.php?a=$1&i=$2  last;
+
rewrite "^/(.*)/album/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2&album=true  last;
+
 
+
rewrite ^/(.*)/?$  /index.php?album=$1  last;
+
}
+
</pre>
+
 
+
In the Gallery Admin page I have set :-
+
  
 
* Admin / Options / Mod ReWrite = <strong>On</strong>
 
* Admin / Options / Mod ReWrite = <strong>On</strong>
 
* Admin / Options / mod_rewrite suffix = <strong>Empty</strong>
 
* Admin / Options / mod_rewrite suffix = <strong>Empty</strong>
  
---
+
<geshi lang="nginx">
 
+
server {
While the above rules <strong>do</strong> provide basic functionality, things like news and pages do not function correctly. This is the reason that I rewrote most of the Apache rules to work with nginx. The only thing missing is the RSS URLs, but I personally don't use them. The rules below can be used with the same admin options as above. This is tested with nginx 1.2.0 and zenPhoto 1.4.2.3.
+
    server_name domain.tld;
 
+
<pre>
+
# Tiny URLs
+
rewrite ^/tiny/([0-9]+)/?$ /index.php?p=$1&t last;
+
 
+
rewrite index\.php$ /index.php last;
+
rewrite ^/page/([0-9]+)/?$ /index.php?page=$1 last;
+
rewrite ^/page/([A-Za-z0-9\-_]+)/?$ /index.php?p=$1 last;
+
rewrite ^/page/([A-Za-z0-9_\-]+)/([0-9]+)/?$ /index.php?p=$1&page=$2 last;
+
rewrite ^/(.*)/page/([A-Za-z0-9_\-]+)/?$ /index.php?album=$1&p=$2 last;
+
 
+
# Search
+
rewrite ^/page/search/fields([0-9]+)/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=$1&words=$2&page=$3 last;
+
rewrite ^/page/search/fields([0-9]+)/(.*)/?$ /index.php?p=search&searchfields=$1&words=$2 last;
+
rewrite ^/page/search/archive/(.*)/([0-9]+)/?$ /index.php?p=search&date=$1&page=$2 last;
+
rewrite ^/page/search/archive/(.*)/?$ /index.php?p=search&date=$1 last;
+
rewrite ^/page/search/tags/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=tags&words=$1&page=$2 last;
+
rewrite ^/page/search/tags/(.*)/?$ /index.php?p=search&searchfields=tags&words=$1 last;
+
rewrite ^/page/search/(.*)/([0-9]+)/?$ /index.php?p=search&words=$1&page=$2 last;
+
rewrite ^/page/search/(.*)/?$ /index.php?p=search&words=$1 last;
+
 
+
# Pages
+
rewrite ^/pages/?$ /index.php?p=pages last;
+
rewrite ^/pages/(.*)/?$ /index.php?p=pages&title=$1 last;
+
 
+
# News
+
rewrite ^/news/?$ /index.php?p=news last;
+
rewrite ^/news/([0-9]+)/?$ /index.php?p=news&page=$1 last;
+
rewrite ^/news/category/(.*)/([0-9]+)/?$  /index.php?p=news&category=$1&page=$2 last;
+
rewrite ^/news/category/(.*)/?$ /index.php?p=news&category=$1 last;
+
rewrite ^/news/archive/(.*)/([0-9]+)/?$ /index.php?p=news&date=$1&page=$2 last;
+
rewrite ^/news/archive/(.*)/?$ /index.php?p=news&date=$1 last;
+
rewrite ^/news/(.*)/?$ /index.php?p=news&title=$1 last;
+
 
+
# Images and stuff
+
rewrite "^/(.*)/image/(thumb|[0-9]{1,4})/([^/\\\]+)$" /zp-core/i.php?a=$1&i=$3&s=$2 last;
+
rewrite ^/(.*)/image/([^/\\\]+)$ /zp-core/i.php?a=$1&i=$2 last;
+
rewrite "^/(.*)/album/(thumb|[0-9]{1,4})/([^/\\\]+)$" /zp-core/i.php?a=$1&i=$3&s=$2&album=true last;
+
 
+
# Catch all for unknown stuff
+
rewrite ^/(.*)/?$ /index.php?album=$1 last;
+
</pre>
+
 
+
<p>
+
Another possible configuration, tested with nginx 1.2 and zenphoto 1.4, without if in location is the  following:
+
</p>
+
<pre>
+
root  /var/www/html/zenphoto; # change this with the root of your zenphoto installation !!!!
+
  
 +
    root  /var/www/zenphoto;
 
     index    index.php;
 
     index    index.php;
  
# pass the PHP scripts to php-fpm server
+
    # pass the PHP scripts to php-fpm server
 
     location ~ \.php$ {
 
     location ~ \.php$ {
                        try_files $uri =404;
+
        try_files $uri =404;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
+
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        include       fastcgi_params;
+
        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_index index.php;
+
        fastcgi_index index.php;
                          fastcgi_pass   php;
+
        fastcgi_pass php;
 
     }
 
     }
  
location @zenphoto {
+
    location @zenphoto {
  
    # experimental rss rules
+
        # experimental rss rules
    rewrite index\.php\?^rss-(.*)&(.*)    /index.php?rss=$1 last;
+
        rewrite index\.php\?^rss-(.*)&(.*)    /index.php?rss=$1 last;
    rewrite index\.php\?^rss-(.*)$        /index.php?rss=$1 last;
+
        rewrite index\.php\?^rss-(.*)$        /index.php?rss=$1 last;
  
    rewrite index\.php$ /index.php last;
+
        rewrite index\.php$ /index.php last;
    rewrite ^/(.*)/page/([A-Za-z0-9_\-]+)/?$ /index.php?album=$1&page=$2 last;
+
        rewrite ^/(.*)/page/([A-Za-z0-9_\-]+)/?$ /index.php?album=$1&page=$2 last;
   
+
    # Images and stuff
+
    rewrite "^/(.*)/image/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2  last;
+
    rewrite ^/(.*)/image/([^/\\\]+)$  /zp-core/i.php?a=$1&i=$2  last;
+
    rewrite "^/(.*)/album/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2&album=true  last;
+
   
+
    # Catch all for unknown stuff
+
    rewrite ^/(.*)/?$ /index.php?album=$1 last;
+
  
 +
        # Images and stuff
 +
        rewrite "^/(.*)/image/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2  last;
 +
        rewrite ^/(.*)/image/([^/\\\]+)$  /zp-core/i.php?a=$1&i=$2  last;
 +
        rewrite "^/(.*)/album/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2&album=true  last;
 +
 +
        # Catch all for unknown stuff
 +
        rewrite ^/(.*)/?$ /index.php?album=$1 last;
 
     }
 
     }
  
location @albums {
+
    location @albums {
 
         rewrite ^/albums/?(.+/?)?$  /$1  redirect;
 
         rewrite ^/albums/?(.+/?)?$  /$1  redirect;
 
     }
 
     }
  
# Admin pages
+
    # Admin pages
location /admin {
+
    location /admin {
    rewrite ^/admin/?$ /zp-core/admin.php redirect;
+
        rewrite ^/admin/?$ /zp-core/admin.php redirect;
 
     }
 
     }
  
location /albums {
+
    location /albums {
    try_files $uri @albums;
+
        try_files $uri @albums;
 
     }
 
     }
  
# Tiny URLs
+
    # Tiny URLs
location /tiny {
+
    location /tiny {
 
         rewrite ^/tiny/([0-9]+)/?$ /index.php?p=$1&t last;
 
         rewrite ^/tiny/([0-9]+)/?$ /index.php?p=$1&t last;
 
     }
 
     }
  
# Page
+
    # Page
location /page {
+
    location /page {
 
         rewrite ^/page/([0-9]+)/?$ /index.php?page=$1 last;
 
         rewrite ^/page/([0-9]+)/?$ /index.php?page=$1 last;
 
         rewrite ^/page/([A-Za-z0-9\-_]+)/?$ /index.php?p=$1 last;
 
         rewrite ^/page/([A-Za-z0-9\-_]+)/?$ /index.php?p=$1 last;
Line 151: Line 64:
 
     }
 
     }
  
# Pages
+
    # Pages
location /pages {
+
    location /pages {
 
         rewrite ^/pages/?$ /index.php?p=pages last;
 
         rewrite ^/pages/?$ /index.php?p=pages last;
 
         rewrite ^/pages/(.*)/?$ /index.php?p=pages&title=$1 last;
 
         rewrite ^/pages/(.*)/?$ /index.php?p=pages&title=$1 last;
 
     }
 
     }
  
# Search
+
    # Search
location /page/search {
+
    location /page/search {
 
         rewrite ^/page/search/fields([0-9]+)/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=$1&words=$2&page=$3 last;
 
         rewrite ^/page/search/fields([0-9]+)/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=$1&words=$2&page=$3 last;
 
         rewrite ^/page/search/fields([0-9]+)/(.*)/?$ /index.php?p=search&searchfields=$1&words=$2 last;
 
         rewrite ^/page/search/fields([0-9]+)/(.*)/?$ /index.php?p=search&searchfields=$1&words=$2 last;
Line 169: Line 82:
 
     }
 
     }
  
# News
+
    # News
location /news {
+
    location /news {
 
         rewrite ^/news/?$ /index.php?p=news last;
 
         rewrite ^/news/?$ /index.php?p=news last;
 
         rewrite ^/news/([0-9]+)/?$ /index.php?p=news&page=$1 last;
 
         rewrite ^/news/([0-9]+)/?$ /index.php?p=news&page=$1 last;
Line 180: Line 93:
 
     }
 
     }
 
          
 
          
# Root
+
    # Root
location / {
+
    location / {
 
         try_files $uri $uri/ @zenphoto;
 
         try_files $uri $uri/ @zenphoto;
     }  
+
     }
   
+
}
 
+
</geshi>
</pre>
+

Latest revision as of 18:47, 5 October 2012

In the Gallery Admin page set:

  • Admin / Options / Mod ReWrite = On
  • Admin / Options / mod_rewrite suffix = Empty
server {
    server_name domain.tld;
 
    root   /var/www/zenphoto;
    index    index.php;
 
    # pass the PHP scripts to php-fpm server
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass php;
    }
 
    location @zenphoto {
 
        # experimental rss rules
        rewrite index\.php\?^rss-(.*)&(.*)    /index.php?rss=$1 last;
        rewrite index\.php\?^rss-(.*)$        /index.php?rss=$1 last;
 
        rewrite index\.php$ /index.php last;
        rewrite ^/(.*)/page/([A-Za-z0-9_\-]+)/?$ /index.php?album=$1&page=$2 last;
 
        # Images and stuff
        rewrite "^/(.*)/image/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2  last;
        rewrite ^/(.*)/image/([^/\\\]+)$  /zp-core/i.php?a=$1&i=$2  last;
        rewrite "^/(.*)/album/(thumb|[0-9]{1,4})/([^/\\\]+)$"  /zp-core/i.php?a=$1&i=$3&s=$2&album=true  last;
 
        # Catch all for unknown stuff
        rewrite ^/(.*)/?$ /index.php?album=$1 last;
    }
 
    location @albums {
         rewrite ^/albums/?(.+/?)?$  /$1  redirect;
    }
 
    # Admin pages
    location /admin {
        rewrite ^/admin/?$ /zp-core/admin.php redirect;
    }
 
    location /albums {
        try_files $uri @albums;
    }
 
    # Tiny URLs
    location /tiny {
        rewrite ^/tiny/([0-9]+)/?$ /index.php?p=$1&t last;
    }
 
    # Page
    location /page {
        rewrite ^/page/([0-9]+)/?$ /index.php?page=$1 last;
        rewrite ^/page/([A-Za-z0-9\-_]+)/?$ /index.php?p=$1 last;
        rewrite ^/page/([A-Za-z0-9_\-]+)/([0-9]+)/?$ /index.php?p=$1&page=$2 last;
    }
 
    # Pages
    location /pages {
        rewrite ^/pages/?$ /index.php?p=pages last;
        rewrite ^/pages/(.*)/?$ /index.php?p=pages&title=$1 last;
    }
 
    # Search
    location /page/search {
        rewrite ^/page/search/fields([0-9]+)/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=$1&words=$2&page=$3 last;
        rewrite ^/page/search/fields([0-9]+)/(.*)/?$ /index.php?p=search&searchfields=$1&words=$2 last;
        rewrite ^/page/search/archive/(.*)/([0-9]+)/?$ /index.php?p=search&date=$1&page=$2 last;
        rewrite ^/page/search/archive/(.*)/?$ /index.php?p=search&date=$1 last;
        rewrite ^/page/search/tags/(.*)/([0-9]+)/?$ /index.php?p=search&searchfields=tags&words=$1&page=$2 last;
        rewrite ^/page/search/tags/(.*)/?$ /index.php?p=search&searchfields=tags&words=$1 last;
        rewrite ^/page/search/(.*)/([0-9]+)/?$ /index.php?p=search&words=$1&page=$2 last;
        rewrite ^/page/search/(.*)/?$ /index.php?p=search&words=$1 last;
    }
 
    # News
    location /news {
        rewrite ^/news/?$ /index.php?p=news last;
        rewrite ^/news/([0-9]+)/?$ /index.php?p=news&page=$1 last;
        rewrite ^/news/category/(.*)/([0-9]+)/?$ /index.php?p=news&category=$1&page=$2 last;
        rewrite ^/news/category/(.*)/?$ /index.php?p=news&category=$1 last;
        rewrite ^/news/archive/(.*)/([0-9]+)/?$ /index.php?p=news&date=$1&page=$2 last;
        rewrite ^/news/archive/(.*)/?$ /index.php?p=news&date=$1 last;
        rewrite ^/news/(.*)/?$ /index.php?p=news&title=$1 last;
    }
 
    # Root
    location / {
        try_files $uri $uri/ @zenphoto;
    }
}