Skip to content

Instantly share code, notes, and snippets.

@cite
Last active Feb 10, 2021
Embed
What would you like to do?
nginx/php-fpm configuration for Gallery3.
[gallery3]
user = vhost-user
group = vhost-group
listen = /tmp/gallery3-example-com.sock
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
# gallery3.example.com definition
server {
server_name gallery3.example.com;
listen 80;
listen [::]:80;
root /srv/www/http-gallery3-example-com;
access_log /var/log/nginx/access-gallery3.example.com.log;
index index.php;
location / {
location ~ /(index\.php/)?(.+)$ {
try_files $uri /index.php?kohana_uri=$2&$args;
location ~ /\.(ht|tpl(\.php?)|sql|inc\.php|db)$ {
deny all;
}
location ~ /var/(uploads|tmp|logs) {
deny all;
}
location ~ /bin {
deny all;
}
location ~ /var/(albums|thumbs|resizes) {
rewrite ^/var/(albums|thumbs|resizes)/(.*)$ /file_proxy/$2 last;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|ttf)$ {
try_files $uri /index.php?kohana_uri=$uri&$args;
expires 30d;
}
}
location = /index.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/tmp/gallery3-example-com.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
}
@GwynethLlewelyn

This comment has been minimized.

Copy link

@GwynethLlewelyn GwynethLlewelyn commented Feb 11, 2014

Awsome! This is a far better nginx configuration than the one from the Gallery3 Wiki. Thank you!

To be "perfect", however, it would need to be able to deal with the album cover thumbnails as well, which have URLs like: http://gallery.betatechnologies.info/var/thumbs/album%20full%20name/.album.jpg?m=1392042977

This might require another rule for things starting with .album.jpg — currently this gives a "forbidden" error. I've tried to tweak the configuration a bit, but without any luck.

@Vilbrekin

This comment has been minimized.

Copy link

@Vilbrekin Vilbrekin commented Apr 12, 2014

It's usually forbidden by generic rules because file starts with a dot. Simply add similar rule before restrictive one :

location ~ /var/thumbs/.*/.album.jpg {}

Hope this helps,
V

@Malachiel87

This comment has been minimized.

Copy link

@Malachiel87 Malachiel87 commented Dec 1, 2016

hi i tried your config, but i see only a blank page.. i know the issue is into php... i amusing this as php block
location = /index.php {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;

@Malachiel87

This comment has been minimized.

Copy link

@Malachiel87 Malachiel87 commented Dec 1, 2016

nvm i fixed it but now i cant login... gallery seem to work

@GwynethLlewelyn

This comment has been minimized.

Copy link

@GwynethLlewelyn GwynethLlewelyn commented May 3, 2020

nvm i fixed it but now i cant login... gallery seem to work

Did you ever manage to login again? Because I cannot...

@GwynethLlewelyn

This comment has been minimized.

Copy link

@GwynethLlewelyn GwynethLlewelyn commented Feb 10, 2021

After years (literally!) of nightmares, I finally found out what was wrong with my configuration...

You have to change this on config.php:

$config["index_page"]=""

... or else, Gallery3 will not work under nginx. Duh! So simple...

Here's the reference (which also cites this very same gist): http://jonamiller.com/2015/02/15/gallery3-on-nginx/

Kudos to @jonmiller for having found a working solution. Gallery3 is now purring like a kitty under PHP 7.4, and soon (hopefully) under 8.0 as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment