【发布时间】:2017-03-28 17:35:26
【问题描述】:
我有一个 Rails 应用程序,在 AWS ELB 后面有一个 NGINX 反向代理。我正在终止 ELB 上的 SSL,并且我已将 NGINX 配置为强制对 HTTP 的任何尝试重写为 HTTPS。此设置工作正常,但我也通过 ECS 为站点提供服务,并且由于 ELB 健康检查在 HTTP 端口 80 上,当它获得重定向并返回 301 时,ELB 健康检查失败并且实例被注销。
如何设置 NGINX 以通过 HTTPS 发送除健康检查文件之外的所有文件?
这是我来自 nginx.conf 的服务器块:
server {
listen 80;
server_name localhost;
root /var/www/html;
location ~ ^elbcheck\.html$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://rails_app;
break;
}
location / {
proxy_redirect off;
proxy_next_upstream error;
if ($http_x_forwarded_proto != "https") {
rewrite ^ https://$host$request_uri? permanent;
}
try_files $uri $uri/ @proxy;
}
location ~* \.(jpg|jpeg|svg|png|gif|ico|css|js|eot|woff|woff2|map)$ {
proxy_cache APP;
proxy_cache_valid 200 1d;
proxy_cache_valid 404 5m;
proxy_ignore_headers "Cache-Control";
expires 1d;
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 https;
add_header X-Cache-Status $upstream_cache_status;
proxy_pass http://rails_app;
}
location @proxy {
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 https;
proxy_pass http://rails_app;
}
}
【问题讨论】:
标签: nginx amazon-elb