Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Related Tools

Notices

Reply
 
Thread Tools Search this Thread
Old 05-27-2016, 03:58 PM   #1
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
Calibre-server reverse proxy issues

Hello there

I am running owncloud on my Ubuntu server and I also want to run calibre. I only want to port-forward 443 (https) and so am trying to reverse proxy into calibre through 443. I have calibre-server running as a daemon on systemd. At the moment I can access calibre quite happily within my LAN when I use 192.168.1.37:8080; however when I go externally I can only access the calibre front page (albeit without css) and I get a 404 not found from cherrypi when I navigate around the pages.

My /etc/apache2/sites-available/000-default.conf file is:
Quote:
<VirtualHost *:443>
ServerName www.dom134.com
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; preload"
</IfModule>
ServerAdmin webmaster@localhost
ServerAlias dom134.com
DocumentRoot /var/www/html
SSLEngine On
SSLCertificateFile <location>
SSLCertificateKeyFile <location>
SSLCACertificateFile <location>
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
ProxyPass /calibre/ http://192.168.1.37:8080/
ProxyPassReverse /calibre/ http://192.168.1.37:8080/
ProxyPreserveHost On
</VirtualHost>
My /lib/systemd/system/calibre.service is:
Quote:
[Unit]
Description=Calibre Service
After=network.target

[Service]
Type=forking
PIDFile=/var/run/calibre-server.pid
ExecStart=/usr/bin/calibre-server \
--daemonize \
--max-cover=600x800 \
--max-opds-items=30 \
--max-opds-ungrouped-items=100 \
--url-prefix /calibre \
--username=dom134_reading \
--password=Password1 \
--port=8080 \
--pidfile=/var/run/calibre-server.pid \
--with-library=/Calibre/

[Install]
WantedBy=multi-user.target
Any help would be greatly appreciated

Last edited by dom134; 05-27-2016 at 03:59 PM. Reason: redacting
dom134 is offline   Reply With Quote
Old 05-27-2016, 04:45 PM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
As per https://manual.calibre-ebook.com/server.html

If you are using ProxyPass, you should set up a dedicated VirtualHost and NOT tell calibre to use an --url-prefix
Or use an --url-prefix and RewriteRule, to serve calibre in a subdirectory of the hosted website.

You seem to be mixing the two together.
eschwartz is offline   Reply With Quote
Advert
Old 05-27-2016, 04:47 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Also, for your systemd unit you can skip --pidfile and --daemonize, and use Type=simple
eschwartz is offline   Reply With Quote
Old 05-28-2016, 05:58 AM   #4
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
Thank you eschwartz,

I have amended my calibre.service file, but I think I am being an ignoramus when it comes to the virtualhost bit. I have created an additional virtualhost as follows, but still to no avail.
Quote:
<VirtualHost *:443>
ServerName www.dom134.com/calibre
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; $
</IfModule>
ServerAdmin webmaster@localhost
ServerAlias dom134.com/calibre
DocumentRoot /var/www/html
SSLEngine On
SSLCertificateFile /location
SSLCertificateKeyFile /location
SSLCACertificateFile /location
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
ProxyPass / http://192.168.1.37:8080/
ProxyPassReverse / http://192.168.1.37:8080/
ProxyPreserveHost On
</VirtualHost>
Would I be better off loading proxy modules rather than using virtualhosts?
dom134 is offline   Reply With Quote
Old 05-28-2016, 11:38 PM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Again: if you have a dedicated VirtualHost (which you do ) then:
  • use ProxyPass (which you are, so good )
but do NOT use:
...

--url-prefix means calibre-server expects all internal urls to appear in http://www.dom134.com/calibre, which is useful in the event that the same server is serving something else in another directory.
Using it means you need to use a RewriteRule to redirect only those subdirectory urls to calibre-server on port 8080.

Since you are using a VirtualHost, you don't need that and can use ProxyPass instead, to forward everything as-is.
You can use an --url-prefix, but it is silly and unnecessary.

An apache ServerName expects to see the servername, not an url. An url is a ServerName followed by an optional directory/filename...

tl;dr Why does your ServerName have a "/calibre" at the end?

Last edited by eschwartz; 05-28-2016 at 11:56 PM.
eschwartz is offline   Reply With Quote
Advert
Old 05-29-2016, 12:46 PM   #6
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
So, I have removed the --url-prefix from the calibre-server, but I still do not understand the virtualhost part.

I would like to have https://www.dom134.com/owncloud go to my owncloud (which it does) and then have https://www.dom134.com/calibre be redirected to my calibre-server running on :8080.

Thank you for your patience!
dom134 is offline   Reply With Quote
Old 05-29-2016, 02:13 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
VirtualHost and ProxyPass is if you want to use https://calibre.dom134.com
RewriteRule and --url-prefix is if you want to use https://www.dom134.com/calibre

So:
  • add back --url-prefix to the calibre-server systemd unit.
  • Put your apache conf back to the way it was before you involved calibre.
  • Make sure your calibre-server is fully functional at http://localhost:8080/calibre.
  • Enable the proxy modules in apache, if they aren't already.
  • As per the calibre manual, add the following to your apache conf:
    Code:
    RewriteEngine on
    RewriteRule ^/calibre/(.*) http://localhost:8080/calibre/$1 [proxy]
    RewriteRule ^/calibre http://localhost:8080 [proxy]
    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1

Last edited by eschwartz; 05-29-2016 at 02:18 PM.
eschwartz is offline   Reply With Quote
Old 05-29-2016, 02:42 PM   #8
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
Hello eschwartz

You must be pulling your hair out! Thank you, I'm currently getting a 503 Service Unavailable so I will check to see if my proxy modules are enabled. Will let you know how it goes.
dom134 is offline   Reply With Quote
Old 05-29-2016, 03:29 PM   #9
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
Having a few issues getting calibre to work now! I'll get back to you soonest.
Anyway
Quote:
RewriteEngine on
RewriteRule ^/calibre/(.*) http://localhost:8080/calibre/$1 [proxy]
RewriteRule ^/calibre http://localhost:8080 [proxy]
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
added to the 443 virtualhost

Quote:
sudo a2enmod proxy.load
sudo a2enmod proxy.http
proxy modules started

Unfortunately I am unable to access http://localhost:8080/calibre and I still get a 503 when accessing through url.

I will grow some and try and work it out!

Thanks!
dom134 is offline   Reply With Quote
Old 05-29-2016, 04:49 PM   #10
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
eschwartz, thank you for your perseverance and patience with me - it all works!

On my calibre-service I had to change the Type from simple back to forking and then it all works. Just for completeness, my calibre-service is:
Quote:
[Unit]
Description=Calibre Service
After=network.target

[Service]
Type=forking
PIDFile=/var/run/calibre-server.pid
ExecStart=/usr/bin/calibre-server \
# --daemonize \
--max-cover=600x800 \
--max-opds-items=30 \
--max-opds-ungrouped-items=100 \
--url-prefix /calibre \
--username=dom134_reading \
--password=Password1 \
--port=8080 \
--pidfile=/var/run/calibre-server.pid \
--with-library=/Calibre/

[Install]
WantedBy=multi-user.target
Next time I will try and RTFM.

Regards dom134
dom134 is offline   Reply With Quote
Old 05-29-2016, 05:19 PM   #11
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Weird. This is my unit file (it is templated with a per-server configuration file) and it works fine:

Code:
[eschwartz@arch ~]$ cat ~/.config/systemd/user/calibre-server@.service
[Unit]
Description=Main calibre server
After=network.target

[Service]
EnvironmentFile=/%h/.config/calibre/servers/%i.conf
ExecStart=/usr/bin/calibre-server \
    --port="${port}" \
    --with-library "${path}" \
    --restriction "${restriction}" \
    --user "${user}" \
    --pass "${pass}"

[Install]
WantedBy=default.target
But the problem did appear to be in the initial calibre server if localhost:8080 didn't work, and making it fork caused it to work???
I cannot think why a forked and daemonized /usr/bin/calibre-server would be any more likely to start than one which represents the main process of the service.

EDIT: Maybe you forgot to remove PIDFile= when you switched to Type=simple and systemd nuked the process out of confusion?

...

Really, it doesn't make a difference whether your daemonize and fork it, or not. It works either way, but Type=simple doesn't make systemctl wait while the server forks before returning. Since systemd natively knows how to track it. Or something.

Last edited by eschwartz; 05-29-2016 at 05:28 PM.
eschwartz is offline   Reply With Quote
Old 05-30-2016, 03:19 PM   #12
dom134
Member
dom134 began at the beginning.
 
Posts: 14
Karma: 10
Join Date: May 2016
Device: none
Still cannot get it to work without using 'forking'

I notice with your:
Quote:
--user "${user}" \
that you are probably not running calibre as root. At the moment I am and I would like to have a different user so that I can get to the logfiles more easily. At the moment I cannot get PID permissions when running other than root. Any suggestions?

Last edited by dom134; 05-30-2016 at 03:23 PM.
dom134 is offline   Reply With Quote
Old 05-30-2016, 04:39 PM   #13
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
--user is one of the arguments to `calibre-server` and refers to the webserver login username/pasword.
Systemd per-user services are better done with `systemctl --user`. Although you can also run the service as root and tell it to invoke the "Exec=" command as a specific "User="

You can use the above systemd service file I posted, with the command
Code:
systemctl start --user calibre-server@LibraryName.service
It uses a configuration file at ~/.config/calibre/servers/LibraryName.conf:
Code:
port="8080"
path="/home/eschwartz/Calibre Libraries/LibraryName"
restriction="optional Virtual Library restriction"
user="some_username"
pass="some_password"

Last edited by eschwartz; 05-30-2016 at 04:44 PM.
eschwartz is offline   Reply With Quote
Reply

Tags
apache, calibre-server, reverse proxy, systemd


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aldiko + Calibre-Server + Reverse Proxy dummkauf Related Tools 4 02-02-2016 02:55 PM
Calibre 2 behind Windows Proxy Server ictstbenedicts Calibre 1 10-10-2012 12:41 PM
need help with reverse proxy server novaris Devices 1 09-10-2012 12:22 PM
Content server apache reverse proxy issue bossanova808 Calibre 13 09-16-2011 09:38 AM
Content Server with Apache Reverse Proxy Caleb666 Calibre 1 08-29-2011 04:20 PM


All times are GMT -4. The time now is 07:19 PM.


MobileRead.com is a privately owned, operated and funded community.