http和https服务器在我的结构中有什么区别?

时间:2020-05-18 19:17:16

标签: node.js express http nginx https

我有一个由nginx在反向代理后面运行的rest节点js应用程序,正确配置了https,其中服务器的配置如下:obs:应用程序是我的路由器。

const httpServer = http.createServer(app);
httpServer.listen(port, () => {
      console.log('hello');
});

nginx作为反向代理的配置如下:

server {
    server_name example.com example.virturian.com.br;

    if ($host !~* example\.com$) {
        return 301 $scheme://example.com$request_uri;
    }

    location / {
    proxy_pass http://localhost:3003;
        proxy_buffering off;
        proxy_set_header Host $host;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com.br/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com.br/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com.br) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name example.com example.virturian.com.br;
    return 404; # managed by Certbot
}

我可以顺利访问应用程序,一切运行正常,我的问题是,考虑到生产环境,仍然有必要按以下方式配置Express服务器吗?

const httpsServer = https.createServer(credentials, app);
httpsServer.listen(port, () => {
  console.log('hello');
});

这两种方法之间有什么区别,即使通过nginx与https一起运行时,是否真的有必要实现为httpsServer?另一个问题,我是否需要使用第二种方法或其他方法侦听端口443?

0 个答案:

没有答案