gotson / komga

Media server for comics/mangas/BDs/magazines/eBooks with API, OPDS and Kobo Sync support
https://komga.org
MIT License
4.02k stars 237 forks source link

Can't load the epub book via HTTPS with a Non-standard port #1735

Closed huonwe closed 1 week ago

huonwe commented 1 week ago

Steps to reproduce

  1. setup nginx https proxy for komga(for some reason, I can't use my 443 port, so listen another port)
  2. open https://yourkomgadomain.com:2560, then open one of my epub books
  3. a white page, loading and loading

Expected behavior

It should show the epub content the browser should request a correct url with a correct port to get the cover of the epub.

Actual behavior

a white page, loading and loading the browser request a wrong url to get the cover of the epub.

Logs

from F12 tool:

xhr.js:195 

        GET https://[fdbe:7775:cd07:0:3e6:ecad:a861:6248]:2560/api/v1/books/0HF8M4TMMKHVJ/previous 404 (Not Found)
(匿名) @ xhr.js:195
xhr @ xhr.js:15
Xa @ dispatchRequest.js:51
_request @ Axios.js:173
request @ Axios.js:40
(匿名) @ Axios.js:199
(匿名) @ bind.js:5
getBookSiblingPrevious @ komga-books.service.ts:116
setup @ EpubReader.vue:511
await in setup
mounted @ EpubReader.vue:148
$a @ vue.runtime.esm.js:3017
zn @ vue.runtime.esm.js:4031
insert @ vue.runtime.esm.js:4423
Y @ vue.runtime.esm.js:6942
(匿名) @ vue.runtime.esm.js:7153
(匿名) @ vue.runtime.esm.js:3769
t @ vue.runtime.esm.js:3875
(匿名) @ vue.runtime.esm.js:3446
(匿名) @ vue.runtime.esm.js:3522
Fn @ vue.runtime.esm.js:4121
(匿名) @ vue.runtime.esm.js:3143
nn @ vue.runtime.esm.js:3065
Promise.then
Qa @ vue.runtime.esm.js:3090
dn @ vue.runtime.esm.js:3155
$n @ vue.runtime.esm.js:4207
(匿名) @ vue.runtime.esm.js:3513
(匿名) @ vue.runtime.esm.js:720
set @ vue.runtime.esm.js:963
(匿名) @ vue-router.esm.js:3005
(匿名) @ vue-router.esm.js:3004
(匿名) @ vue-router.esm.js:2414
(匿名) @ vue-router.esm.js:2263
(匿名) @ vue-router.esm.js:2402
t @ vue-router.esm.js:2084
t @ vue-router.esm.js:2091
Ge @ vue-router.esm.js:2095
(匿名) @ vue-router.esm.js:2397
t @ vue-router.esm.js:2084
(匿名) @ vue-router.esm.js:2088
(匿名) @ vue-router.esm.js:2384
(匿名) @ vue-router.esm.js:2127
(匿名) @ vue-router.esm.js:2203
Promise.then
(匿名) @ vue-router.esm.js:2150
(匿名) @ vue-router.esm.js:2171
(匿名) @ vue-router.esm.js:2171
$e @ vue-router.esm.js:2170
(匿名) @ vue-router.esm.js:2106
c @ vue-router.esm.js:2362
t @ vue-router.esm.js:2087
t @ vue-router.esm.js:2091
(匿名) @ vue-router.esm.js:2088
(匿名) @ vue-router.esm.js:2384
(匿名) @ router.ts:312
c @ vue-router.esm.js:2362
t @ vue-router.esm.js:2087
t @ vue-router.esm.js:2091
Ge @ vue-router.esm.js:2095
(匿名) @ vue-router.esm.js:2392
(匿名) @ vue-router.esm.js:2260
i @ vue-router.esm.js:2585
index.js:63041 

        GET https://[fdbe:7775:cd07:0:3e6:ecad:a861:6248]/api/v1/books/0HF8M4TMMKHVJ/resource/OEBPS/Text/cover.xhtml net::ERR_CONNECTION_REFUSED
precessContentForIframe @ index.js:63041
navigate @ index.js:63881
await in navigate
navigate @ index.js:63960
await in navigate
loadManifest @ index.js:62406
await in loadManifest
start @ index.js:62036
create @ index.js:61648
load @ index.js:65742
await in load
setup @ EpubReader.vue:424
await in setup
mounted @ EpubReader.vue:148
$a @ vue.runtime.esm.js:3017
zn @ vue.runtime.esm.js:4031
insert @ vue.runtime.esm.js:4423
Y @ vue.runtime.esm.js:6942
(匿名) @ vue.runtime.esm.js:7153
(匿名) @ vue.runtime.esm.js:3769
t @ vue.runtime.esm.js:3875
(匿名) @ vue.runtime.esm.js:3446
(匿名) @ vue.runtime.esm.js:3522
Fn @ vue.runtime.esm.js:4121
(匿名) @ vue.runtime.esm.js:3143
nn @ vue.runtime.esm.js:3065
Promise.then
Qa @ vue.runtime.esm.js:3090
dn @ vue.runtime.esm.js:3155
$n @ vue.runtime.esm.js:4207
(匿名) @ vue.runtime.esm.js:3513
(匿名) @ vue.runtime.esm.js:720
set @ vue.runtime.esm.js:963
(匿名) @ vue-router.esm.js:3005
(匿名) @ vue-router.esm.js:3004
(匿名) @ vue-router.esm.js:2414
(匿名) @ vue-router.esm.js:2263
(匿名) @ vue-router.esm.js:2402
t @ vue-router.esm.js:2084
t @ vue-router.esm.js:2091
Ge @ vue-router.esm.js:2095
(匿名) @ vue-router.esm.js:2397
t @ vue-router.esm.js:2084
(匿名) @ vue-router.esm.js:2088
(匿名) @ vue-router.esm.js:2384
(匿名) @ vue-router.esm.js:2127
(匿名) @ vue-router.esm.js:2203
Promise.then
(匿名) @ vue-router.esm.js:2150
(匿名) @ vue-router.esm.js:2171
(匿名) @ vue-router.esm.js:2171
$e @ vue-router.esm.js:2170
(匿名) @ vue-router.esm.js:2106
c @ vue-router.esm.js:2362
t @ vue-router.esm.js:2087
t @ vue-router.esm.js:2091
(匿名) @ vue-router.esm.js:2088
(匿名) @ vue-router.esm.js:2384
(匿名) @ router.ts:312
c @ vue-router.esm.js:2362
t @ vue-router.esm.js:2087
t @ vue-router.esm.js:2091
Ge @ vue-router.esm.js:2095
(匿名) @ vue-router.esm.js:2392
(匿名) @ vue-router.esm.js:2260
i @ vue-router.esm.js:2585
index.js:63041 

        Uncaught (in promise) TypeError: Failed to fetch
    at e.precessContentForIframe (index.js:63041:11)
    at e.navigate (index.js:63881:14)
    at async e.navigate (index.js:63958:30)
    at async e.loadManifest (index.js:62405:36)
    at async e.start (index.js:62035:12)
    at async e.create (index.js:61653:5)
    at async e.load (index.js:65742:13)
    at async r.setup (EpubReader.vue:424:12)

Komga version

1.14.0

Operating system

Client: Windows 11 Edge; Server: Raspberrypi 4

Installation method

Docker

Other details

It should request https://xxx.xxx.xxx:2560/api/v1/books/0HF8M4TMMKHVJ/resource/OEBPS/Text/cover.xhtml rather than https://xxx.xxx.xxx/api/v1/books/0HF8M4TMMKHVJ/resource/OEBPS/Text/cover.xhtml But if don't use https, the web know to request the correct URL, and if assign the port to 443 in nginx, this problem also doesn't appear.

If open https://xxx.xxx.xxx:2560/api/v1/books/0HF8M4TMMKHVJ/resource/OEBPS/Text/cover.xhtml in browser, it shows the correct cover of the epub.

nginx config:

server {
    listen 2560 ssl http2;
    listen [::]:2560 ssl http2;
    server_name xxx.xxx.xxx;

    error_page 497 https://$host:2560$request_uri;
    ssl_certificate /etc/nginx/conf.d/_lan.crt;
    ssl_certificate_key /etc/nginx/conf.d/_lan.key;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Range $http_range;
        proxy_set_header If-Range $http_if_range;
        proxy_pass http://127.0.0.1:25600;
        }
}

Acknowledgements

huonwe commented 1 week ago

I found that add proxy_set_header X-Forwarded-Host $http_host; to nginx can fix this problem :).