首页 > 解决方案 > 负载均衡器上终止 HTTPS 时的 ServiceStack 安全 cookie

问题描述

在 ServiceStack 中,该HostConfig标志UseSecureCookies = true将在通过 HTTPS 传输时将 cookie 标记为安全。

然而,在现实世界中,通常在负载均衡器处终止 SSL,然后在内部使用 HTTP(即Internet --https--> LB --http--> application

在这种情况下如何实现安全的 HTTPS cookie?

标签: servicestack

解决方案


安全 cookie只能通过 HTTPS 传输,ServiceStack 仍将在 SSL 终止代理之后发出安全 cookie,前提是它正确设置了X-Forwarded-Proto: https下游 HTTP 标头。

例如,这里是SSL Terminated nginx 反向代理的典型示例:

server {
    listen       80;
    server_name my-app.org;

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_cache_bypass $http_upgrade;
        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;
        proxy_buffering off;
        proxy_ignore_client_abort off;
        proxy_intercept_errors on;

        client_max_body_size 500m;
    }
}

推荐阅读