I want to launch my web application with https. I have created self signed key and certificate with this command:
openssl req -newkey rsa:2048 -sha256 -nodes -keyout key.key -x509 -days 365 -out public.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=my.example.com"
This created to me key.key
nad public.pem
files.
Now I want to assign them to my express application:
const app = express();
const https = require('https');
const http = require('http');
const fs = require('fs');
app.get('/*', (req, res) => {
res.send("Hello");
});
const options = {
key: fs.readFileSync(`${__dirname}/key.key`), // Path to file with PEM private key
cert: fs.readFileSync(`${__dirname}/public.pem`) // Path to file with PEM certificate
};
https.createServer(options, app).listen(443);
http.createServer(app).listen(80);
When I open my my.example.com/
it successfully shows me Hello
message text.
Howver, when I open it like this https://my.example.com/
my browser does not open this page and shows ERR_SSL_PROTOCOL_ERROR
error message.
What did I miss?