Create a Basic HTTPS Server (using TLS)
·
227 words
·
2 minutes read
This post isn’t about the benefits or why you should be using https, instead it’s just about how to setup and use it with a basic Go web server. Compared with a basic http server there are two main differences. Firstly we need to generate some certificates and secondly we need to change our code to use the certificates and communicate over a TLS connection.
Step 1: Commands to make self-signed certificates
openssl genrsa -out https-server.key 2048
openssl ecparam -genkey -name secp384r1 -out https-server.key
Finally self-sign the certificate and specify information like country, name and email:
openssl req -new -x509 -sha256 -key https-server.key -out https-server.crt -days 3650
Step 2: Update our Go Code
|
|
Note: remember to actually connect to it over https, e.g. https://localhost:8080