Websockets giving 521 Error

I have setup a Websocket with python websockeets, wraped it in ssl with the right orgin certificate, have strict mode enabled but i get a 521 Error. Nginx on the otherhand works fine and i can acsess it. Here is the code:

import json,subprocess,uuid,requests,asyncio,ssl
from time import sleep
from websockets.server import serve
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain('/home/certs/certificate.pem', '/home/certs/privatekey.key')
async def echo(websocket):
    async for message in websocket:
        await websocket.send(message)
        print(message)
async def main():
    async with serve(echo, "localhost", 8443,ssl=ssl_context) as socket:

        await asyncio.Future()  # run forever

asyncio.run(main())