View Single Post
Old 11-17-2017, 02:09 PM   #1
haertig
Wizard
haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.haertig ought to be getting tired of karma fortunes by now.
 
Posts: 1,897
Karma: 31522252
Join Date: Sep 2017
Device: PW3, Fire HD8 Gen7, Moto G7, Sansa Clip v2, Ruizu X26
Need help: Using NGINX as reverse-proxy for Calibre

I am working to get Calibre reverse-proxied by NGINX webserver. The basic NGINX setup as presented in the documentation works well (note that NGINX is hosted on 10.192.0.26 and calibre-server is running on a different computer, 10.192.0.2):

Code:
server {
        listen 80 default_server;
        server_name localhost 10.192.0.26;
        proxy_set_header X-Forwarded-For $remote_addr;
        location /calibre/ {
                proxy_buffering off;
                proxy_pass http://10.192.0.2:8080$request_uri;
        }
        location /calibre {
                rewrite /calibre /calibre/ permanent;
        }
}
And this is how I'm starting the calibre-server on 10.192.0.2:

Code:
calibre-server --url-prefix /calibre --num-per-page=999 --port 8080
The above works fine. But I want to tweak something. And it's an NGINX thing, not a Calibre thing. However, I figured that some folks here have fronted Calibre with NGINX and may know NGINX.

Currently, if I go to http://10.192.0.26/calibre (that's the NGINX server URL) then it jumps to http://10.192.0.2:8080/calibre (that's the calibre-server URL). Great. But what I want is if the user enters this:

Code:
http://10.192.0.26/calibre
... then NGINX translates that to:

Code:
http://10.192.0.2:8080/calibre/#library_id=Calibre&panel=book_list&sort=author_sort.asc,series.asc&vl=Novels
... so that the user does not hit the Calibre default screen where they then have to manually choose a library, a virtual library, and a sort order. I want to automatically give them my preferred view (library, vl, sort). Then later they can change all this is the want, but they start out with MY defaults, not Calibres.

I know I could just have them bookmark the full URL (including fragment) that I am proposing to rewrite above. But this is something I think I should be able to do automatically in NGINX. But being new to NGINX, I don't know how.

In a nutshell:

If user hits NGINX with generic (no fragment at the end of the URI) http://10.192.0.26/calibre, then rewrite to add the fragment that defines my preferred library/vl/sort.

But if user hits NGINX with a Calibre URI with a fragment on the end, then leave it as-is and don't try to rewrite.

After getting this rewrite fixed, next up I will use my DDNS name, httpS with LetsEncrypt cert, and client cert authentication. One step at a time though. I'm just working on the rewrite and basic reverse proxy stuff first.
haertig is offline   Reply With Quote