'C# HTTPS Server on Ubuntu
I'm trying to get an HTTPS connection working on Ubuntu from my C# HTTP server. I've enabled HTTPS in my HTTPListener as you would on Windows, however I am unable to establish a connection.
From the docs:
If you create an HttpListener using https, you must select a Server Certificate for that listener. Otherwise, an HttpWebRequest query of this HttpListener will fail with an unexpected close of the connection.
I am seeing exactly this happen. The docs suggest:
You can configure Server Certificates and other listener options by using Network Shell (netsh.exe). See Network Shell (Netsh) for more details. The executable began shipping with Windows Server 2008 and Windows Vista.
Since I am on Ubuntu and my server is running Ubuntu Server, I do not have access to this tool. How do I achieve the same effect in Ubuntu?
Solution 1:[1]
This is dependent on the backend web server being used. On Ubuntu, you'd probably be using Kestrel. For Kestrel, an SSL certificate can be defined using:
"Kestrel": {
"Certificates": {
"Default": {
"Path": "<path>/fullchain.pem",
"KeyPath": "<path>/privkey.pem"
}
},
"Endpoints": {
"Http": {
"Url": "http://*:80"
},
"Https": {
"Url": "https://*:443"
}
}
in appsettings.json
For more information about how to set up SSL for Kestrel refer to: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ethan |