ankicommunity / ankicommunity-sync-server

A personal Anki sync server (so you can sync against your own server rather than AnkiWeb)
GNU Affero General Public License v3.0
883 stars 81 forks source link

Anki 2.1.49 will not sync via https proxy #154

Open pajot opened 1 year ago

pajot commented 1 year ago

I have anki-sync-server running behind an nginx web server.

The nginx configuration looks like this:

server {
        listen       27701 ssl;
        server_name   dummy.net;

        ssl_certificate /etc/letsencrypt/live/dummy.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/dummy.net/privkey.pem;

        location / {
            proxy_http_version 1.0;
            proxy_pass         http://127.0.0.1:27702/;
            client_max_body_size 222M;
        }
    }

nginx listens on port 27701 and anki-sync-server on 27702.

tcp       LISTEN     0          511                                    0.0.0.0:27701               0.0.0.0:*                                                                                                                            
tcp       LISTEN     0          5                                    127.0.0.1:27702               0.0.0.0:*         users:(("python",pid=223409,fd=3))                                                                               

I configure the add-on manually using the instructions for > 2.1.28:

import os

addr = "https://dummy.net:27701/" # put your server address here
os.environ["SYNC_ENDPOINT"] = addr + "sync/"
os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/"

But when I try to sync, I get an error dialog telling me to check the database and try again. On the server side, I see this in the nginx error.log:

2022/11/16 00:09:41 [info] 199330#0: *35105 client sent plain HTTP request to HTTPS port while reading client request headers, client: <address>, server: dummy.net, request: "POST /sync/hostKey HTTP/1.1", host: "dummy.net:27701"

And nothing in the ankisyncd console output.

If I query the server with curl https://dummy.net:27701, I get Anki Sync Server

If I query it with curl https://dummy.net:27701/sync/hostKey, I get A server error occurred. Please contact the administrator.

and

[2022-11-16 00:42:57,861]:INFO:ankisyncd.http:127.0.0.1 "GET /sync/hostKey HTTP/1.0" 500 59

in the ankisyncd console output.

(But this is probably because my API request is not formatted correctly.)

It would appear that Anki is not speaking https, despite having specified it in the add-on configuration.

dglava commented 1 year ago

Have you tried it with this addon: https://ankiweb.net/shared/info/358444159 ? I am also using an NGINX reverse proxy with HTTPS (pretty much the same configuration as you) with Anki 2.1.54 and I have

{
    "syncaddr": "https://domain.com/anki/"
}

in the addon's settings and it works without issues.

pajot commented 1 year ago

Yes, I've tried it with custom sync server redirector and I get this error message when syncing:

error decoding response body: expected value at line 1 column 1⁩