Gallery3 on nginx

So I've recently migrated from apache2/mpm-prefork to nginx/php5-fpm with the help of a couple tutorials, and for the main WordPress site that I host, everything is operational; some tweaking lies ahead certainly, but it's operational nonetheless.

I then switched my focus to getting some personal sites working, the first being an installation of Gallery3. First hurdle: php.ini settings, in particular short-tags need to be on. No problem, create a .user.ini file with the proper configuration and that's done. Second hurdle: rewrites. Gallery3 uses an index.php dispatcher which requires some rewrite configuration. I'll admit I'm bad at this (rewrites in general but in particular nginx config rewrites/logic) and, after searching and trial/error, I've got it working. Except it uses if () within location.

Here's my config, if anyone can help me migrate to try_files, I'd be appreciative:

server {
        listen 80;
        server_name site.com;

        access_log /var/log/nginx/ionly.servebeer_access.log;
        error_log /var/log/nginx/ionly.servebeer_error.log;

        root /home/tom/sites/site.com;
        index index.php index.html index.htm;

        if ($http_host != "site.com") {
                rewrite ^ http://site.com$request_uri permanent;
        }

        include global/restrictions.conf;

        # Additional rules go here.
        location ~.php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /home/tom/sites/site.com$fastcgi_script_name;
                include fastcgi_params;
        }

        location /gallery3/ {
                if (!-e $request_filename) {
                        rewrite ^/gallery3/index.php/(.+)$ /gallery3/index.php?kohana_uri=$1 last;
                        rewrite ^/gallery3/(.+)$ /gallery3/index.php?kohana_uri=$1 last;
                        rewrite ^/gallery3/$ /gallery3/index.php?kohana_uri=/ last;
                }

        }
}

Edit:

I could not get the suggestions found here to work. All 404.

Edit2:

I also saw this, but I don't understand it. Can anybody comment?

2 Replies

Hello rawsted,

Please, did you find solution for this?

I also have an wordpress website, and gallery as a photo gallery extension of the website, and can´t make it work.

Regards,

Tony

I have Gallery 3 running on nginx on Linode. I am moving to ZenPhoto, but the old site is still up and running now.

# Site config file
server {
        server_name example.com;
        root /folder/to/example.com;
        include conf.sites/gallery3.conf;
}

# www redirect
server {
        server_name www.example.com;
        return 301 http://example.com$request_uri;
}
## file gallery3.conf
## Gallery 3 Configuration Based on https://gist.github.com/cite/6419890

index index.php;

client_max_body_size 20M;

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:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      include fastcgi_params;
    }
}

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct