【发布时间】:2017-07-21 01:08:23
【问题描述】:
安装 SSL/https 密钥后,X-CSRFToken 被删除。我还设置了http2。在 Https 之前一切正常,但现在我得到 403,因为缺少 CSRF 令牌。找不到解决此特定问题的信息。感谢您的帮助。
support
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
server_name site.io www.site.io;
# Use the Let's Encrypt certificates
ssl_certificate /etc/letsencrypt/live/site.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.io/privkey.pem;
# Include the SSL configuration from cipherli.st
include /etc/nginx/snippets/ssl-params.conf;
add_header Strict-Transport-Security max-age=500;
access_log /home/nodejs/site.io/resuma_io_access.log;
error_log /home/nodejs/site.io/resuma_io_error.log;
root /home/nodejs/site.io/www/dist/client;
location ~ ^/(api|user|auth|socket.io-client|sitemap.xml) {
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;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_ssl_session_reuse off;
proxy_redirect off;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
proxy_http_version 1.1;
proxy_pass_header X-CSRFToken;
add_header X-Frame-Options SAMEORIGIN;
sendfile off;
proxy_pass http://nodejs_upstream;
}
}
【问题讨论】:
-
您能找到解决方法吗?我相信我也有同样的问题。
-
如果您的设置与上述相同,您可能会在其他地方遇到问题。它对我不起作用,因为 X-CSRF 令牌是由后端在任何第一次请求时生成和设置的。但是由于所有文件都由 nginx 提供,因此在访客用户的初始页面加载时没有请求后端。作为一种解决方法,我发出一个服务器请求以在初始页面加载时创建令牌。
标签: node.js ssl nginx reverse-proxy