Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 11-17-2017, 02:09 PM   #1
haertig
Addict
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: 366
Karma: 2383254
Join Date: Sep 2017
Device: Nook ST, Fire Gen7, PaperWhite3, iPhone 5S
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
Old 11-17-2017, 06:09 PM   #2
haertig
Addict
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: 366
Karma: 2383254
Join Date: Sep 2017
Device: Nook ST, Fire Gen7, PaperWhite3, iPhone 5S
After doing more research, I see why my attempts thus far have no worked.

In the following:
Code:
http://10.192.0.2:8080/calibre/#library_id=Calibre&panel=book_list&sort=author_sort.asc,series.asc&vl=Novels
... everything past the # is called a "fragment", and it is NOT passed to the server with the URI request. Fragments are handled on the client end. So me trying to rewrite something BEING SENT TO THE SERVER (via proxy_pass in this case) would never work.

So while I initially thought this should be something I could do in NGINX, I am not so sure now. I will have to do more research. But if anyone here knows the answer, I'd love some advice/suggestions. Thanks.

p.s. Maybe I can do something with a 301 redirect sent back to the client. I'll trying messing around with that. The thing is, if these fragments are not sent to the server, then NGINX would not know if the client is hitting it "naked", or with a fragment. So NGINX would not know if it should pass the request through (if it already had a fragment), or rewrite/redirect it with a 301 (if it was "naked"). Hmmm...

Last edited by haertig; 11-17-2017 at 06:15 PM.
haertig is offline   Reply With Quote
Advert
Old 11-17-2017, 06:20 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 33,405
Karma: 10205094
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes, fragments translate into ajax api calls made by the client to the server. The contents of the ajax calls are controlled by the fragment. They are not in any way processed by the server. So redirecting to them in a proxy is not going to work.
kovidgoyal is online now   Reply With Quote
Old 11-18-2017, 04:06 PM   #4
haertig
Addict
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: 366
Karma: 2383254
Join Date: Sep 2017
Device: Nook ST, Fire Gen7, PaperWhite3, iPhone 5S
Why not simply this:

Code:
server {
        listen 80;       
        location /calibre {
                proxy_buffering off;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_pass http://10.192.0.2:8080$request_uri;
        }
}
Rather than what the Calibre documentation recommends:

Code:
server {
        listen 80;
        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;
        }
}
I have tested both configs, and cannot see any difference in how they function from the web browser client end-user viewpoint. Things seem to work just fine either way. Is there some special case that I am not testing that requires the second, longer specification?

I have tested with these URLs:

Code:
http://10.192.0.26/calibre
http://10.192.0.26/calibre/
http://10.192.0.26/calibre/#library_id=Calibre&panel=book_list&sort=author_sort.asc,series.asc&vl=Novels
[ Note: Calibre Content Server started like this: calibre-server --url-prefix /calibre --num-per-page=999 --port 8080 ]

[ Note: 10.192.0.26:80 runs the NGINX reverse proxy (Raspberry Pi3/Raspbian), 10.192.0.2:8080 runs the caliber-server (LinuxMint18 Sarah) ]
haertig is offline   Reply With Quote
Old 11-18-2017, 05:00 PM   #5
haertig
Addict
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: 366
Karma: 2383254
Join Date: Sep 2017
Device: Nook ST, Fire Gen7, PaperWhite3, iPhone 5S
Hold on. It looks like Calibre stores local data that makes it APPEAR that things are working, even when they are not. So my above tests were not valid. If I clear all Calibre local data, I get quite different results (errors). I need to clear out all Calibre data (more than just cache and cookies) between each test.
haertig is offline   Reply With Quote
Advert
Old 11-18-2017, 08:54 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 33,405
Karma: 10205094
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes, the content server is designed to work offline as well, which is why the home page does not show a list of books in a library but a list of books that have been opened and stored locally.
kovidgoyal is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre-server reverse proxy issues dom134 Related Tools 12 05-30-2016 04:39 PM
Nginx Calibre Proxy Ackis Calibre 2 04-19-2016 01:48 PM
Aldiko + Calibre-Server + Reverse Proxy dummkauf Related Tools 4 02-02-2016 02:55 PM
need help with reverse proxy server novaris Devices 1 09-10-2012 12:22 PM
Content Server with Apache Reverse Proxy Caleb666 Calibre 1 08-29-2011 04:20 PM


All times are GMT -4. The time now is 05:59 AM.


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