Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
Created March 29, 2025 17:18
Show Gist options
  • Save hopeseekr/f044136e791513be061f0c8b27d329cc to your computer and use it in GitHub Desktop.
Save hopeseekr/f044136e791513be061f0c8b27d329cc to your computer and use it in GitHub Desktop.
Optimized Calibre-web Apache reverse proxy
# Prequiste: For security, set Calibre to listen to 127.0.0.4:8083:
# Edit `/etc/systemd/system/multi-user.target.wants/calibre-web.service`:
# Change to `ExecStart=/usr/lib/calibre-web/cps.py -i 127.0.0.4`
# sudo systemctl daemon-reload
# sudo systemctl restart calibre-web
<VirtualHost *:443>
ServerName read.your.site
# SSL Configuration
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/read.your.site/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/read.your.site/privkey.pem
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder on
# Logging
ErrorLog /var/log/apache2/read.your.site.error.log
CustomLog /var/log/apache2/read.your.site.log combined
# Common proxy settings
ProxyPreserveHost On
ProxyRequests Off
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
TimeOut 300
# Main proxy configuration
ProxyPass / http://127.0.0.4:8083/
ProxyPassReverse / http://127.0.0.4:8083/
# Special configuration for upload endpoints
<LocationMatch "/(upload|book/add|upload-new)">
# Increased body size limit specifically for book uploads
LimitRequestBody 209715200
# SECURITY NOTE: Same security considerations as in Nginx config
ProxyPass http://127.0.0.4:8083/
ProxyPassReverse http://127.0.0.4:8083/
</LocationMatch>
# WebSocket support
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) ws://127.0.0.4:8083/$1 [P,L]
</VirtualHost>
@hopeseekr
Copy link
Author

hopeseekr commented Mar 29, 2025

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