gotson / komga

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

Nginx: Can't read the epub book on HTTPS #1453

Closed yatounoneko closed 5 months ago

yatounoneko commented 5 months ago

Steps to reproduce

  1. setup nginx https proxy for komga
  2. open https://yourkomgadomain.com read your epub book
  3. show the white page now

Expected behavior

It should be get the nomral page on https://yourkomgadomain.com/book/0FExxxxxxxx/read-epub?incognito=false

Actual behavior

Now show white page and get a error msg from F12 tool

inspector.js:7 Mixed Content: The page at 'https://yourkomgadomain.com/book/0FExxxxxxxx/read-epub?incognito=false' was loaded over HTTPS, but requested an insecure resource 'http://yourkomgadomain.com/api/v1/books/0FExxxxxxxx/resource/OEBPS/Text/Cover.html'. This request has been blocked; the content must be served over HTTPS.

Logs

2024-03-20T00:27:48.517+08:00 WARN 202296 --- [o-25600-exec-78] o.s.web.servlet.PageNotFound : No mapping for GET /book/0FExxxxxxxx/read-epub

Komga version

1.10.3

Operating system

Windows server 2019

Installation method

jar

Other details

The same problem also in : Title.html Contents.html chapter0~X.html

FYI

No response

Acknowledgements

PatrickTCB commented 5 months ago

Have you maybe set this via an environment variable? Can you post the relevant environment variables?

These urls are set in komga-webui/src/functions/urls.ts. Unless the dev environment variables have been set they should be https whenever loaded from https.

const fullUrl = process.env.VUE_APP_KOMGA_API_URL
  ? process.env.VUE_APP_KOMGA_API_URL
  : window.location.origin + window.resourceBaseUrl
const baseUrl = process.env.NODE_ENV === 'production' ? window.resourceBaseUrl : '/'

const urls = {
  origin: !fullUrl.endsWith('/') ? `${fullUrl}/` : fullUrl,
  originNoSlash: fullUrl.endsWith('/') ? fullUrl.slice(0, -1) : fullUrl,
  base: !baseUrl.endsWith('/') ? `${baseUrl}/` : baseUrl,
  baseNoSlash: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl,
} as Urls
gotson commented 5 months ago

You are probably missing forward headers like X-Forwarded-Proto

Check the closed issues, there's numerous people who can't configure nginx properly for reverse proxy. Or better, use Caddy, which works outside the box.

yatounoneko commented 5 months ago

Oh, you are right! I hadn’t searched for nginx in the closed issues because I thought the problem was not about Nginx.

It turns out you were right; I found that issue #1322 has a solution for this problem. I tried adding the config proxy_set_header X-Forwarded-Proto $scheme; to my nginx reverse proxy.

Now my epub book has been restored. Thanks for your help!

FlashDoggy commented 4 months ago

You are probably missing forward headers like X-Forwarded-Proto

Check the closed issues, there's numerous people who can't configure nginx properly for reverse proxy. Or better, use Caddy, which works outside the box.

Hi, I also faced this problem but i'm using apache as reverseproxy, and according to the X-Forwarded-Proto. I added this sentence RequestHeader setifempty X-Forwarded-Proto "https" and it works.

Hope this could work for you, I think it's the problem of the https head misuse.