Announcement

#1 2015-05-04 13:27:45

bubobubo
Guest

Nginx experts - need help with rewrites for Piwigo

Hello/Hi/Greetings,

(I posted this on stackoverflow with nginx tag but it doesn't get any views/attention at all so I reproduce  it here.)

I got into some issues with links that should contain and index.php like this: foto.domain.net/index.php/category/3

It seems like a simple task, rewriting /index/category/3 to /index.php/category/3, but no matter what I write in those rewrites, I end up with a 404 error and a never changing nginx error log entry that looks like this:

Code:

pen() "/srv/http/foto/index/category/3" failed (2: No such file or directory), client: 94.242.246.23, server: ~^(?<prefix>www)?\.?(?<subdomain>[a-z]+)?\.domain\.net$, request: "GET /index/category/3 HTTP/1.1", host: "foto.domain.net", referrer: "http://foto.domain.net/"

The error log looks the same even if I add junk to the rewrite line such as:

Code:

rewrite ^/index((/|$).*)$ /JUNK_index.php$1 last;

So the rewrite part is faulty, somehow but I can't figure it out...

Code:

server {
    listen       80;
    server_name  domain.net;
    return       301 $scheme://www.domain.net$request_uri;
}

server {
  listen 80;
  server_name "~^(?<prefix>www)?\.?(?<subdomain>[a-z]+)?\.domain\.net$";
  root /srv/http/$subdomain;

  location @rewrites {
       rewrite ^/picture((/|$).*)$ /picture.php$1 last;
       rewrite ^/index((/|$).*)$ /index.php$1 last;
       # The following is needed for batch operations which use i.php
       rewrite ^/i((/|$).*)$ /i.php$1 last;
  }

  location /$subdomain {
       index index.php index.html;
       try_files $uri $uri.php $uri/ @rewrites;
  }
  
  location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
       try_files $script_name = 404;
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       fastcgi_param PATH_INFO $path_info;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
  }
}
 

#2 2015-05-05 01:24:54

bubobubo
Guest

Re: Nginx experts - need help with rewrites for Piwigo

I managed to get Piwigo and Nginx running after many hours... This is because I'm a complete noob when it comes to webservers. So this is my working config, if anyone ever cares, for a Piwigo installation at subdomain foto in subdirectory foto:

Code:

server {
    listen 80;
    server_name www.foto.domain.net foto.domain.net;
    root /srv/http/foto;

    error_log /var/log/nginx/foto.domain.net.error.log;
    access_log /var/log/nginx/foto.domain.net.access.log;

    location / {
        index index.php;

        rewrite ^/index((/|$).*)$ /index.php?$1 permanent;
        rewrite ^/picture((/|$).*)$ /picture.php?$1 permanent;

        try_files $uri $uri/ =404;
    }

    location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

One question though, are there any known security problems with having index.php?/category/1 in the URL?

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2019 · Contact