gpt4 book ai didi

SSL 不适用于 Elastic Load Balancer 和 Nginx

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:36 25 4
gpt4 key购买 nike

我最近购买了一个 SSL 证书,我正在尝试使用 Nginx EC2 实例将它加载到我的 Elastic Load Balancer 上。

该网站未加载任何内容,我的错误日志显示此错误:在 SSL 握手时监听 SSL 端口的服务器中未定义“ssl_certificate”

亚马逊网站上的所有健康检查都通过了,所以我不确定是什么问题。 SSL 证书也已正确上传到我的 ELB。我的 nginx 代理文件如下所示:

server {    
listen 80;
listen 443 default_server ssl;

rewrite ^(.*) https://$host$1 permanent;

client_max_body_size 4G;
client_header_timeout 60;
client_body_buffer_size 1K;
client_header_buffer_size 1k;
server_name %(DOMAINS)s %(EC2_INSTANCES)s;
keepalive_timeout 20;
root %(PROJECT_PATH)s;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}

非常感谢任何建议!提前致谢!

编辑 - - -

网站现在显示纯白页面,但当我检查元素时(通过 Chrome)出现 503 错误。不确定这是否起作用,但我认为信息越多越好。

最佳答案

在您的 ELB 中,将流量从 443 端口重定向到 80 端口,并在您的虚拟主机中执行此操作:

server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
client_max_body_size 4G;
client_header_timeout 60;
client_body_buffer_size 1K;
client_header_buffer_size 1k;
server_name %(DOMAINS)s %(EC2_INSTANCES)s;
keepalive_timeout 20;
root %(PROJECT_PATH)s;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
set $is_https 'off';
if ($http_x_forwarded_proto ~ 'https') {
set $is_https 'on';
}
proxy_set_header HTTPS $is_https;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}

如果您要在 ELB 中终止 SSL,则无需检查虚拟主机中的 SSL。您只需要检查 http_x_forwarded_proto header 并将其传递给后端即可。

关于SSL 不适用于 Elastic Load Balancer 和 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33611783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com