【发布时间】:2017-01-29 20:24:57
【问题描述】:
我们有一个公共 AWS ELB,它像这样重定向流量:
HTTP 80 HTTP 9001
TCP 443 TCP 9001
目标实例是使用 nginx 容器运行 docker 的 AWS ECS 实例。
Docker 正在转发 9001 -> 8080,而 nginx 正在监听 8080。 这是 nginx 配置的片段:
server {
ssl on;
ssl_certificate /etc/nginx/mydomain.crt;
ssl_certificate_key /etc/nginx/mydomain.key;
listen 8080;
server_name %{ROUTER_CLEARCARE_SERVER_NAME};
access_log /var/log/nginx/access.log logstash_json;
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
set $target_web "web.mydomain.com:80";
location / {
proxy_read_timeout 180;
proxy_connect_timeout 2;
proxy_send_timeout 180;
keepalive_timeout 180;
resolver 10.10.0.2 valid=30s;
proxy_set_header Host $host;
proxy_pass http://$target_web;
proxy_set_header X-Unique-ID $request_id;
}
}
我需要在 nginx 容器上进行 SSL 终止,因为我们有多个域的多个证书,并且我们使用具有不同超时时间的基于路径的路由(ELB 仅支持单个证书,而 ALB 不支持基于路径的路由不同超时和证书)。
这里是关键:nginx 只能监听一个端口(我们正在使用一个名为 Empire 的工具将 nginx 容器部署到 AWS ECS,他们目前只支持这种配置)。
nginx 可以在单个端口上支持 http 和 https 吗?
现在,使用该配置,我在尝试点击 http://example.com 时收到此错误:
The plain HTTP request was sent to HTTPS port
当我尝试点击 https://example.com 时出现此错误,我收到此错误:
mydomain.com redirected you too many times.
【问题讨论】:
标签: nginx amazon-elb