docker - aws ecs 上的 nginx docker 容器 >> 纯 HTTP 请求已发送到 HTTPS 端口

标签 docker nginx amazon-ecs aws-load-balancer aws-application-load-balancer

我有一个在 aws ecs ec2 实例上运行的前端角度应用程序,它们都连接到网络负载均衡器的 TCP 端口 443 和 80。我将在这个具有多个域名的 nginx docker 容器上配置许多虚拟主机。在 ecs 服务中,用于负载平衡的容器指定为端口 443。我们必须选择容器的端口 443 或 80 进行负载平衡。 https://prnt.sc/pocu41。在 https 上,网站加载正常。但是在 http 上我收到错误

The plain HTTP request was sent to HTTPS port

我打算在 docker 容器上使用 ssl 证书,而不是在负载均衡器上使用 ssl。如果我在负载均衡器上选择 ssl,那么我们需要在应用程序负载均衡器默认证书中使用多域 ssl,当有数百个域时可能不可行。

我的 Nginx 配置文件是这样的

server {
        listen 80;
        server_name  example.com;

        root   /usr/share/nginx/html/docroot;
        index  index.html index.htm;
        include /etc/nginx/mime.types;

        gzip on;
        gzip_min_length 1000;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        location / {
            try_files $uri $uri/ /index.html;
        }
    }


server {
    listen 443 ssl;
    listen [::]:443 ssl;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example.com/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;

    server_name  example.com;
    root           /usr/share/nginx/html/docroot;
    index          index.html;
    location / {
                try_files $uri $uri/ =404;
        }

}

知道我们如何解决这种情况吗?

最佳答案

I am planning to use the ssl certificate on the docker container and not the ssl on the load balancer. If I choose ssl on the load balancer then we need to use the multidomain ssl in application load balancer default certificate and may not feasible when there are hundreds of domain.

你的这个假设似乎不正确,你可以从 LB 创建 * 证书或者你可以配置 multiple from ACM as well .您可以将 AWS ACM 与负载均衡器一起使用,而且它完全免费,为什么我要费心在应用程序级别管理 SSL?如果不需要 NLB,我可以使用应用程序 LB 进行重定向,为什么我应该在应用程序级别打开端口 80?

AWS Certificate Manager 定价

Public SSL/TLS certificates provisioned through AWS Certificate Manager are free. You pay only for the AWS resources you create to run your application.

certificate-manager-pricing

其次,使用 NLB 有什么特殊原因吗?对于网络应用程序,我永远不会选择网络平衡器,NLB 对于 TCP 级别的通信很有意义,但我会选择 application LB用于提供高级路由的 HTTP 通信,例如基于主机的路由、重定向和基于路径的路由,这将消除对 Nginx 的需求。

容器专为轻量级任务而设计,AWS 建议使用 300-500MB 左右的内存,对 CPU 的建议也相同。

您知道在容器级别终止 SSL 的成本吗?

SSL 流量可能是计算密集型,因为它需要对流量进行加密和解密。 SSL 依靠公钥加密来加密客户端和服务器之间的通信,从而安全地跨网络发送消息。

在 LB 级别终止 SSL 的优势

需要在负载平衡器处终止 SSL,因为解密是资源和 CPU 密集型的。 将解密负担放在负载平衡器上,使服务器能够将处理能力用于应用程序任务,这有助于提高性能。它还简化了 SSL 证书的管理。

new-tls-termination-for-network-load-balancers

ssl-termination

enter image description here

10-tips-to-improve-the-performance-of-your-aws-application

因此,基于此,我不会按照@Linpy 的建议回答您的问题,如果您仍然想去,可能会有所帮助,您也可以这样做dealing-with-nginx-400-the-plain-http-request-was-sent-to-https-port-error

关于docker - aws ecs 上的 nginx docker 容器 >> 纯 HTTP 请求已发送到 HTTPS 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58587976/

相关文章:

ubuntu - ubuntu 12.04.2 lts 中的乘客 nginx 模块服务名称注册

docker - Tomcat 的 Nginx Rverse 代理(简单的是……?否)

docker - 如何将更新的 Docker 镜像部署到 Amazon ECS 任务?

docker,mariadb 不是从 "init"开始,基于 debian :stable

docker - redis-sentinel 抛出错误 : "Can' t resolve master instance hostname.“

ruby-on-rails - 如何使用 rails、nginx 和乘客配置 `Access-Control-Allow-Origin`?

amazon-web-services - AWS ECS : Invalid service in ARN (Service: AmazonECS; . ..)

mongodb - 在其他容器中公开 mongo 端口

Docker 未运行...失败

amazon-web-services - AWS : Changing host port in EC2 based ECS task definition using new ECS Console