在负载均衡器上终止 HTTPS 时的 ServiceStack 安全 cookie
ServiceStack Secure cookie when HTTPS is terminated on the load balancer
在 ServiceStack 中,HostConfig
标志 UseSecureCookies = true
将在通过 HTTPS 传输时将 cookie 标记为安全。
然而,在现实世界中,通常在负载均衡器处终止 SSL,然后在内部使用 HTTP(即 Internet --https--> LB --http--> application
)
在这种情况下如何实现安全的 HTTPS cookie?
Secure cookies 只能通过 HTTPS 传输,ServiceStack 仍会在 SSL 终止代理后发出安全 Cookie,前提是它正确设置 X-Forwarded-Proto: https
下游 HTTP Header.
例如这是 SSL Terminated nginx reverse proxy:
的典型示例
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;
}
}
在 ServiceStack 中,HostConfig
标志 UseSecureCookies = true
将在通过 HTTPS 传输时将 cookie 标记为安全。
然而,在现实世界中,通常在负载均衡器处终止 SSL,然后在内部使用 HTTP(即 Internet --https--> LB --http--> application
)
在这种情况下如何实现安全的 HTTPS cookie?
Secure cookies 只能通过 HTTPS 传输,ServiceStack 仍会在 SSL 终止代理后发出安全 Cookie,前提是它正确设置 X-Forwarded-Proto: https
下游 HTTP Header.
例如这是 SSL Terminated nginx reverse proxy:
的典型示例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;
}
}