Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Calibreweb Nginx configuration doesn't work for IPv6 #1071

Open
Irishsmurf opened this issue Sep 8, 2023 · 2 comments
Open

[BUG] Calibreweb Nginx configuration doesn't work for IPv6 #1071

Irishsmurf opened this issue Sep 8, 2023 · 2 comments
Labels

Comments

@Irishsmurf
Copy link
Contributor

Irishsmurf commented Sep 8, 2023

What happened?

Steps to reproduce:

  1. Install nginx.
    • box install nginx
  2. Install CalibreWeb
    • box install calibreweb
  3. Attempt to load https://<website>/calibreweb from an IPv6 Address
  4. 500 Internal Error
    • From Nginx Error logs:
    •  2023/09/08 16:45:16 [crit] 2382422#2382422: *490 bind(<IPv6 IP ADDRESS>) failed (97: Address family not supported by 
       protocol) while connecting to upstream, client: <IPv6 IP ADDRESS>, server: <SERVER HOSTNAME>, 
       request: "GET /calibreweb HTTP/2.0", upstream: "http://127.0.0.1:8083/calibreweb", host: "<SERVER HOSTNAME>", referrer: 
       "https://<SERVER HOSTNAME>/"
      

Expected results:

Page loads.

Results occur:

CalibreWeb is inaccessible if the client is using IPv6.


I fixed this by modifying the nginx configuration in calibreweb.conf to:

location /calibreweb {
        proxy_pass              http://127.0.0.1:8083;
        proxy_set_header        Host $proxy_host;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Host $host;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_http_version      1.1;
        proxy_set_header        Upgrade $http_upgrade;
        proxy_set_header        Connection $http_connection;

        proxy_set_header        X-Scheme        $scheme;
        proxy_set_header        X-Script-Name   /calibreweb;  # IMPORTANT: path has NO trailing slash
}

Swizzin commit

9dc0c50

What OS are you using?

Debian 10 (Buster)

What architecture is your OS?

amd64

Relevant logs and output

2023/09/08 16:45:16 [crit] 2382422#2382422: *490 bind(<IPv6 IP ADDRESS>) failed (97: Address family not supported by 
       protocol) while connecting to upstream, client: <IPv6 IP ADDRESS>, server: <SERVER HOSTNAME>, 
       request: "GET /calibreweb HTTP/2.0", upstream: "http://127.0.0.1:8083/calibreweb", host: "<SERVER HOSTNAME>", referrer: 
       "https://<SERVER HOSTNAME>/"
@Irishsmurf Irishsmurf added the bug label Sep 8, 2023
@liaralabs liaralabs changed the title [BUG] CalibreWeb's Nginx configuration doesn't work for IPv6 [BUG] Nginx configuration doesn't work for IPv6 Sep 8, 2023
@liaralabs liaralabs changed the title [BUG] Nginx configuration doesn't work for IPv6 [BUG] Calibreweb Nginx configuration doesn't work for IPv6 Sep 8, 2023
@liaralabs
Copy link
Member

        proxy_set_header        Upgrade $http_upgrade;
        proxy_set_header        Connection $http_connection;

Shouldn't be necessary -- these are for websocket upgrades, which I don't think calibre web makes use of.

It looks like the magic happens in translating

proxy_set_header        Host            $http_host;

to

proxy_set_header        Host $proxy_host;

And potentially adding the X-Forwarded-Host (though that mostly depends on whether calbre web even cares about this header)

@Irishsmurf
Copy link
Contributor Author

Irishsmurf commented Sep 10, 2023

Turns out it's not the Host header - http_host/proxy_host are essentially the same.

It's the proxy_bind bit:

  1. Client hits the host via the IPv6 interface
  2. nginx will then bind to $server_addr, which will be the server's IPv6 NIC Address.
  3. Attempts to connect with calibreweb's upstream address - http://127.0.0.1:8083
  4. This is an IPv4 address - the protocol mismatch between nginx's IPv6 bind() address, and the upstream server causes a critical internal error.
  5. 500 Internal Error

I've sent a PR (#1072) which just removes this setting - and falls back to the default behavior (where it binds with the same protocol as upstream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants