【发布时间】:2019-04-10 17:25:44
【问题描述】:
我正在尝试使用 docker-machine 使用堆栈 nginx+gunicorn+django 创建 ec2 实例。我有一个面向 Internet 的应用程序负载均衡器,它有两个目标组(绿色/蓝色),以防止新部署中的任何停机(新部署被部署到未使用的组,并且在一切检查完毕时负载均衡器组发生更改)
在端口 80 上一切正常,但是当我尝试为端口 443 添加一个监听器并为该域提供亚马逊颁发的证书时,我无法让它工作。我还需要从 Nginx 内部获取证书吗?我需要 Nginx 来监听 443 端口吗?目标?
负载均衡器:
+------------+-----------------------------+----------------+
| Listener ID| Rules. | SSL Certificate|
+------------+-----------------------------+----------------+
| HTTP: 80 | Default: forwarding to blue.| N/A. |
+------------+-----------------------------+----------------+
| HTTPS: 443 | Default: forwarding to blue.|Default: (ACM). |
+------------+-----------------------------+----------------+
目标:
+------------+--------------+--------------+--------------+---------------+
| Name | Port | Protocol | Target type | Load Balancer |
+------------+--------------+--------------+--------------+---------------+
| Blue | 80 | HTTP | instance | loadbalancer |
+------------+--------------+--------------+--------------+---------------+
| Green | 80 | HTTP | instance | |
+------------+--------------+--------------+--------------+---------------+
我的 Nginx 配置:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
upstream app {
server django:5000;
}
server {
listen 80;
charset utf-8;
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
location / {
try_files $uri @proxy_to_app;
}
# django app
location @proxy_to_app {
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;
proxy_pass http://app;
}
}
}
【问题讨论】:
-
如果是Elastic Load Balancer,需要安装SSL证书。
-
是的,负载均衡器安装了 Amazon 颁发的 SSL 证书,并在 443 的端口侦听器上使用。
-
您看到了什么确切的错误?您在哪里看到交通正在停止?在 ALB 端或 Nginx 级别?您可以让 ALB 在 443 上侦听并进行 SSL 终止并在 80 上执行后端 Nginx。
-
哇,愚蠢的错误! docker-machine 使用的我的安全组不会自动允许端口 443,因为它没有在 docker-compose 中指定。添加规则,现在一切正常!
-
哦。高兴的。解决了!!