Talking Mango
Talking Mango

Reputation: 51

Why do I have to type the ":80" in https://localhost:80 for my website to load?

I recently secured my website on node.js to use https instead of just plain http. However, once I did this, I realized that I had to type out the :80 suffix if I wanted to get to my website to load. Why is this? Doesn't chrome default to port 80 and shouldn't https://localhost suffice?

const port = 80;

https.createServer({
    key: fs.readFileSync('./private/ssl/server.key'),
    cert: fs.readFileSync('./private/ssl/server.cert')
}, app)
    .listen(port, function () {
        console.log('Server running on port: ' + port);
    });

app.get('/', (req, res) => {
    res.sendFile('index.html', { root: path.join(__dirname, './') });
});

app.use(express.static('./public'));```

Upvotes: 0

Views: 632

Answers (2)

Thomas Hirsch
Thomas Hirsch

Reputation: 2338

Be aware that HTTPS uses port 443 by default, and that's probably the source of your confusion.

If you specify both https and :80 in your browser's address bar, you are making an HTTPS request to port 80, which is unusual. What kind of reply you will be getting depends on your server's configuration.

Upvotes: 1

SLaks
SLaks

Reputation: 887857

The default port for HTTPS is 443, not 80.

Upvotes: 3

Related Questions