seblucas / cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
1.43k stars 229 forks source link

Can't download from COPS for Calibre #383

Closed Irv007 closed 6 years ago

Irv007 commented 6 years ago

Hello,

I can browse and download my E-Books with calibre. I can browse my E-Books with COPS. I can read my E-Books with the Reader built-in in COPS.

But I can't download my E-Books with COPS because of an error in my browser (Google Chrome): 404 Not Found nginx/1.10.3 (Ubuntu)

URL in Google Chrome, when displaying the error:

$config['cops_use_url_rewriting'] = "1"; => http://mydomain.eu:55555/download/56095/Alexander%20von%20Humboldt%20und%20die%20Erfindung%20d%20-%20Wulf%2C%20Andrea.epub
$config['cops_use_url_rewriting'] = "0"; => http://mydomain.eu:55555/mpoint1/Calbib1/Wulf%2C%20Andrea/Alexander%20von%20Humboldt%20und%20die%20Erfindung%20der%20Natur%20%2856133%29/Alexander%20von%20Humboldt%20und%20die%20Erfindung%20d%20-%20Wulf%2C%20Andrea.epub

There is no error in error.log of nginx.

Any Idea, what is going wrong and how I can fix it?

with best regards, Irv

my system

  1. Ubuntu 16.04
  2. nginx 1.10.3
  3. COPS 1.1.1
  4. PHP 7.1
  5. calibre 3.14
  6. behind a router
  7. access through WAN
  8. Calibre-Directory has rights 777
  9. Example-Book above has rights 777 (plus all directories above on the way to Calibre-Directory)
  10. Calibre-Directory: /var/www/mpoint1/Calbib1
  11. Cops-Direcotry: /var/www/cops
  12. /etc/nginx/mime.types contains application/epub+zip epub;

nginx-conf-file

  1 server {
  2         listen 55555;
  3         server_name mydomain.eu:55555;
  4         root /var/www/cops;
  5         index index.php;
  6
  7         fastcgi_pass_header Authorization;
  8
  9         location / {
 10                 try_files $uri $uri/ =404;
 11         }
 12
 13         location ~ \.php$ {
 14             fastcgi_pass unix:/run/php/php7.1-fpm.sock;
 15             include snippets/fastcgi-php.conf;
 16             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 17         }
 18
 19         location ~ /\.ht {
 20                 deny all;
 21         }
 22
 23         location /Calbib1 {
 24               root /var/www/mpoint1;
 25                internal;
 26         }
 27 }

config_local.php

 1 <?php
  2     if (!isset($config))
  3         $config = array();
  4
  5     /*
  6      * The directory containing calibre's metadata.db file, with sub-directories
  7      * containing all the formats.
  8      * BEWARE : it has to end with a /
  9      */
 10      $config['calibre_directory'] = '../mpoint1/Calbib1/';
 11
 12
 13
 14    /*
 15      * The URL to the calibre internal directory you specified in your nginx site
 16      * config file.
 17      */
 18     $config['calibre_internal_directory'] = '/Calbib1/';
 19
 20
 21
 22     /*
 23      * Catalog's title
 24      */
 25     $config['cops_title_default'] = "COPS1";
 26
 27     /*
 28      * use URL rewriting for downloading of ebook in HTML catalog
 29      * See README for more information
 30      *  1 : enable
 31      *  0 : disable
 32      */
 33     $config['cops_use_url_rewriting'] = "0";
 34
 35
 36      /*
 37      * Wich header to use when downloading books outside the web directory
 38      * Possible values are :
 39      *   X-Accel-Redirect   : For Nginx
 40      *   X-Sendfile         : For Lightttpd or Apache (with mod_xsendfile)
 41      *   No value (default) : Let PHP handle the download
 42      */
 43     $config['cops_x_accel_redirect'] = "X-Accel-Redirect";
 44
 45
 46     /*
 47      * URL to access the COPS page
 48      */
 49     $config['cops_full_url'] = 'mydomain.eu:55555';
 50
 51     /*
 52      * Default timezone
 53      * Check following link for other timezones :
 54      * http://www.php.net/manual/en/timezones.php
 55      */
 56     $config['default_timezone'] = "Europe/Vienna";
 57
 58
 59
 60 /*
 61     $config['cops_basic_authentication'] = array();
 62 */
 63
 64
 65     $config['cops_basic_authentication'] = array('username' => '???', 'password' => '???');
seblucas commented 6 years ago

I guess this has to do with your X-Accel-Redirect configuration, please try to remove your $config['cops_x_accel_redirect'] from config_local to confirm my theory.

Then if you need X-Accel-Redirect then you can read more thoroughly Nginx doc about that (https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/) especially the difference between alias and root (as I'm guessing is the problem here)

Irv007 commented 6 years ago

I removed the line with $config['cops_x_accel_redirect']. To be sure, I restarted the whole machine.

The behaviour did not change. The errormessage is the same.

seblucas commented 6 years ago

Please change $config['calibre_directory'] = '../mpoint1/Calbib1/'; to the full path /var/www/mpoint1/Calbib1

And for now also disable url rewriting to avoid facing all the problems at once

Irv007 commented 6 years ago

config_local.php:

<?php
    if (!isset($config))
        $config = array();

    /*
     * The directory containing calibre's metadata.db file, with sub-directories
     * containing all the formats.
     * BEWARE : it has to end with a /
     */
/*
     $config['calibre_directory'] = '../mpoint1/Calbib1/';
*/
     $config['calibre_directory'] = '/var/www/mpoint1/Calbib1/';

   /*
     * The URL to the calibre internal directory you specified in your nginx sit                    e
     * config file.
     */
    $config['calibre_internal_directory'] = '/Calbib1/';

    /*
     * Catalog's title
     */
    $config['cops_title_default'] = "COPS1";

    /*
     * use URL rewriting for downloading of ebook in HTML catalog
     * See README for more information
     *  1 : enable
     *  0 : disable
     */
    $config['cops_use_url_rewriting'] = "0";

     /*
     * Wich header to use when downloading books outside the web directory
     * Possible values are :
     *   X-Accel-Redirect   : For Nginx
     *   X-Sendfile         : For Lightttpd or Apache (with mod_xsendfile)
     *   No value (default) : Let PHP handle the download
     */
/*
    $config['cops_x_accel_redirect'] = "X-Accel-Redirect";
*/
    $config['cops_x_accel_redirect'] = "";

    /*
     * URL to access the COPS page
     */
    $config['cops_full_url'] = 'xbuch.eu:55555';

    /*
     * Default timezone
     * Check following link for other timezones :
     * http://www.php.net/manual/en/timezones.php
     */
    $config['default_timezone'] = "Europe/Vienna";

/*
    $config['cops_basic_authentication'] = array();
*/

    $config['cops_basic_authentication'] = array('username' => '???', 'password' => '???');
seblucas commented 6 years ago

Can you confirm that you see the book cover in COPS ?

Can you check your PHP error logs ?

Irv007 commented 6 years ago

Yes, I can see the book cover in COPS.

I think, the errors go to /var/log/nginx. This file says:

2018/01/06 10:43:40 [error] 1335#1335: *31 FastCGI sent in stderr: "PHP message: PHP Warning:  fopen(/Calbib1/Ildiko von Kurthy/Hilde_ Mein neues Leben als Frauchen. Sehnsucht an der Leine, Irrsinn auf der Hundewiese und s (56140)/Hilde_ Mein neues Leben als Frauchen. Sehn - Ildiko von Kurthy.epub): failed to open stream: No such file or directory in /var/www/cops/fetch.php on line 117
PHP message: PHP Warning:  filesize(): stat failed for /Calbib1/Ildiko von Kurthy/Hilde_ Mein neues Leben als Frauchen. Sehnsucht an der Leine, Irrsinn auf der Hundewiese und s (56140)/Hilde_ Mein neues Leben als Frauchen. Sehn - Ildiko von Kurthy.epub in /var/www/cops/fetch.php on line 118
PHP message: PHP Warning:  fpassthru() expects parameter 1 to be resource, boolean given in /var/www/cops/fetch.php on line 119" while reading response header from upstream, client: 5.159.0.139, server: xbuch.eu:55555, request: "GET /fetch.php?data=56110&type=epub&id=56140 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "xbuch.eu:55555", referrer: "http://xbuch.eu:55555/index.php?page=10"
ubuntu@ip-172-31-19-142:/var/log/nginx$
Irv007 commented 6 years ago

it works now.

rewriting = 0. redirect = X-Accel-Redirect

Hurra!!!

seblucas commented 6 years ago

Still feel strange that it does not work without X-Accel-Redirect

Are you sure PHP / Nginx are running as the same Unix user ; www-data ?

But it works and that's good

Irv007 commented 6 years ago
ubuntu@ip-172-31-19-142:/var/www/cops$ ps -edalf | grep -e nginx -e php
4 S root      1314     1  0  80   0 - 93084 -      09:59 ?        00:00:00 php-fpm: master process (/etc/php/7.1/fpm/php-fpm.conf)
4 S root      1321     1  0  80   0 - 72429 -      09:59 ?        00:00:00 php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)
1 S root      1334     1  0  80   0 - 30819 -      09:59 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
5 S www-data  1335  1334  0  80   0 - 30976 -      09:59 ?        00:00:00 nginx: worker process
5 S www-data  1347  1321  0  80   0 - 72429 -      09:59 ?        00:00:00 php-fpm: pool www
5 S www-data  1348  1321  0  80   0 - 72429 -      09:59 ?        00:00:00 php-fpm: pool www
5 S www-data  1350  1314  0  80   0 - 95693 -      09:59 ?        00:00:01 php-fpm: pool www
5 S www-data  1351  1314  0  80   0 - 95468 -      09:59 ?        00:00:02 php-fpm: pool www
5 S www-data  2264  1314  0  80   0 - 95468 -      10:49 ?        00:00:01 php-fpm: pool www
0 S ubuntu    2276  2057  0  80   0 -  3237 pipe_w 10:59 pts/8    00:00:00 grep --color=auto -e nginx -e php
ubuntu@ip-172-31-19-142:/var/www/cops$
Irv007 commented 6 years ago

I'm very happy. Thank you.

seblucas commented 6 years ago

That's still strange (and it will haunt me for some time) but I'll still close the issue