简体   繁体   English

为什么必须在https:// localhost:80中键入“:80”才能加载我的网站?

[英]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. 最近,我在node.js上确保我的网站使用https而不是纯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. 但是,一旦这样做,我意识到如果要访问我的网站,则必须输入:80后缀。 Why is this? 为什么是这样? Doesn't chrome default to port 80 and shouldn't https://localhost suffice? chrome不会默认使用端口80,并且https:// localhost是否足够?

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'));```

HTTPS的默认端口是443,而不是80。

Be aware that HTTPS uses port 443 by default, and that's probably the source of your confusion. 请注意,默认情况下HTTPS使用端口443,这可能是造成混乱的原因。

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. 如果在浏览器的地址栏中同时指定https:80 ,则您正在向端口80发出HTTPS请求,这很常见。 What kind of reply you will be getting depends on your server's configuration. 您将获得什么样的答复取决于服务器的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要将我的节点 js 网站保护到在 HTTP 的默认 80 端口上运行的 HTTPS - I need to secure my node js website to HTTPS running on the default 80 port of HTTP 为什么部署到Elastic Beanstalk的NodeJS服务器在端口80上接收HTTPS流量? - Why is my NodeJS server deployed to Elastic Beanstalk receiving HTTPS traffic on port 80? 为什么Chrome删除localhost:80的端口号? - Why does Chrome remove port number for localhost:80? 我的 https:443 服务器如何为 http:80 提供服务? - How is my https:443 server serving http:80 also? 端口80的Https和SSL问题 - Https and SSL issue with port 80 为什么我的应用程序在端口80而不是端口3000上侦听,因为我将其设置为在docker容器内运行? - Why does my app listen on port 80 instead of port 3000 as I set it running inside docker container? 我如何在80端口上使用nodemon运行我的nodejs - How can I run my nodejs with nodemon on port 80 通过NGINX(localhost)在端口80上运行Ghost - Running Ghost on port 80 through NGINX (localhost) 服务器可以在localhost上运行,但不能在端口80上使用ip - Server works on localhost but not with ip on port 80 如何在端口 80 上运行 Node.js? - How do I run Node.js on port 80?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM