Node.js NodeJs头盔hsts配置

Node.js NodeJs头盔hsts配置,node.js,express,Node.js,Express,我对NodeJs不太熟悉,但我被要求支持NodeJs应用程序,以防发现安全漏洞。我在NodeJs上使用一个expressweb服务器。要求使用HST。因此,我安装了头盔模块并添加了以下代码: 应用程序使用(helmet.hsts()) 我相信hsts模块将强制客户端通过https进行连接,并且不支持通过http进行连接 问:这是否意味着现在NodeJs express服务器必须获得SSL证书 Qu可以这样做,但这不是要求。 如果您想这样做,请导入https并从中创建服务器,而不是http: co

我对NodeJs不太熟悉,但我被要求支持NodeJs应用程序,以防发现安全漏洞。我在NodeJs上使用一个expressweb服务器。要求使用HST。因此,我安装了头盔模块并添加了以下代码:

应用程序使用(helmet.hsts())

我相信hsts模块将强制客户端通过https进行连接,并且不支持通过http进行连接

问:这是否意味着现在NodeJs express服务器必须获得SSL证书


Qu

可以这样做,但这不是要求。 如果您想这样做,请导入
https
并从中创建服务器,而不是
http

const-app=require('express')();
常量https=require('https');
常数fs=要求('fs');
// ...
https.createServer({
key:fs.readFileSync('./key.pem'),
证书:fs.readFileSync('./cert.pem'),
密码短语:“您的密码短语”
},app)
.听(443);
另一个流行的解决方案是,仍然使用普通HTTP运行应用程序,但在应用程序前面使用代理(例如NGINX、HAProxy或Apache)来执行SSL并与客户端建立连接

例如,这是NGINX(应用程序运行在上)的一个示例

server {

    listen 443;
    server_name yourhost.domain.com;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    location / {

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://localhost:3000;
      proxy_read_timeout  90;

      proxy_redirect      http://localhost:3000 https://yourhost.domain.com;
    }
  }