【问题标题】:enabling hsts for node byproxy with nginx not working在 nginx 不工作的情况下为节点代理启用 hsts
【发布时间】:2021-06-16 05:23:20
【问题描述】:

我的网络服务器使用 nodejs 托管在 AWS 上,我使用 aws ELB 进行 http -> https 重定向和它处理 ssl,但在我的网络服务器中,nodejs 是由 nginx 代理的,所以我试图在 /etc 上启用 HSTS /nginx/站点可用/默认。但它不起作用。

server {
  listen       80;
  server_name  localhost;

  location / {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header Content-Security-Policy "default-src 'self' www.google-analytics.com ajax.googleapis.com www.google.com google.com gstatic.com www.gstatic.com connect.facebook.net facebook.com;";
    add_header X-XSS-Protection "1; mode=block";
    add_header Referrer-Policy "origin";
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

【问题讨论】:

  • 请编辑问题以阐明“不工作”的含义

标签: node.js nginx


【解决方案1】:

我通过运行带有 --hsts 标志的 certbot 解决了这个问题。

certbot --nginx --hsts

然后出现了 strict-transport-security 标头

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 2017-04-26
    相关资源
    最近更新 更多