【发布时间】:2018-10-11 15:34:43
【问题描述】:
在运行 Nginx 的 EC2 实例前使用 AWS Elastic Load Balancer(应用程序类型)时,我遇到了 HTTPS 请求的“502 Bad Gateway”问题。 Nginx 在每个实例上充当为 Python 应用程序(Pyramid 框架)提供服务的服务员服务器的反向代理。我正在尝试在 ELB 上使用 TLS 终止,以便 EC2 实例仅处理 HTTP。这是粗略的设置:
客户端 HTTPS 请求 > ELB(监听 443,转发到后端的 80) > Nginx 监听端口 80(在 Ec2 实例上) > 转发到女服务员/Pyramid(在同一个 ec2 实例上)
当我在 HTTPS 上发出请求时,我收到 502 错误。但是,当我发出常规 HTTP 请求时,我得到了预期的响应(与上述设置相同,但 ELB 正在侦听端口 80)。
一些附加信息: ELB 运行状况检查正在运行。 所有 VPC/安全组都配置正确(我相信)。 我正在使用 AWS 上的标准设置/演练在 ELB 上使用 AWS 证书。 我通过 SSH 连接到 Ec2 实例,在 Nginx 访问日志中,看起来 HTTPS 请求仍然是加密的?还是一些编码问题?
这里是 EC2 实例上的 nginx.conf:
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /etc/nginx/access.log;
sendfile on;
# Configuration containing list of application servers
upstream app_servers {
server 127.0.0.1:6543;
}
server {
listen 80;
server_name [MY-EC2-SERVER-NAME];
# Proxy connections to the application servers
# app_servers
location / {
proxy_pass http://app_servers;
proxy_redirect off;
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-Host $server_name;
}
}
}
【问题讨论】:
标签: amazon-web-services nginx reverse-proxy amazon-elb