node.js - 我必须包括 :433 to access HTTPS on AWS Elastic Beanstalk

标签 node.js nginx https amazon-elastic-beanstalk aws-ebs

我在 AWS Elastic Beanstalk 上设置 HTTPS 时遇到问题。我当前的问题是,尽管 HTTPS 正在运行,但用户必须包含端口号。

我的目标是让“example.xyz”重定向到“https://example.xyz”。 目前我必须转到地址:“example.xyz:433”才能访问 EB。

目前,我仅尝试为 EB 负载均衡器使用 HTTPS。它将通过 HTTP 与 EC2 通信。理想情况下,我会进行端到端加密,但一次一步,你知道。

设置:

  • 64 位 Amazon Linux/4.5.0 上的 Node.js v8.11.1
  • 经典负载均衡器
  • 我的日志正在发送到 CloudWatch
  • 我有自己的域名 - 通过 Route 53 购买。
  • 我已使用 ALIAS 将流量从域重定向到我的 AWS EB:

     name: ""
     Type: A IPv4 (default)
     Routing Policy: Simple (default)
     Evaluate Target Health: No
    
  • 我已使用 ACM 设置证书

  • 我使用以下 *.config 来让负载均衡器监听 HTTPS:

    option_settings:
      aws:elb:listener:433:
        SSLCertificateId: arn:aws:acm:us-east-X:XXXXXXXX:certificate/XXXXXXXXX
        ListenerProtocol: HTTPS
        InstancePort: 80
    

生成的端口设置(来自 EB 控制台):

- Port: 80
- Protocol: HTTP
- Instance Port: 80
- SSL: ---
- Enabled: On

- Port: 433
- Protocol: HTTPS
- Instance Port: 80
- SSL: XXXXX
- Enabled: On
<小时/>

我已经使用 Apache 和 Nginx 来尝试这个。在浏览互联网后,我找到了获取这些服务器以将 HTTP 强制转换为 HTTPS 的说明。以下是我使用过的示例:

Apache :

files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
        RewriteEngine On
        <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
        </If>

Nginx:

    files:
  "/tmp/45_nginx_https_rw.sh":
    owner: root
    group: root
    mode: "000644"
    content: |
      #! /bin/bash

      CONFIGURED=`grep -c "return 301 https" /opt/elasticbeanstalk/support/conf/webapp_healthd.conf`

      if [ $CONFIGURED = 0 ]
        then
          sed -i '/listen 80;/a \    if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }\n' /opt/elasticbeanstalk/support/conf/webapp_healthd.conf
          logger -t nginx_rw "https rewrite rules added"
          exit 0
        else
          logger -t nginx_rw "https rewrite rules already set"
          exit 0
      fi
container_commands:
  00_appdeploy_rewrite_hook:
    command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/appdeploy/enact
  01_configdeploy_rewrite_hook:
    command: cp -v /tmp/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact
  02_rewrite_hook_perms:
    command: chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_https_rw.sh
  03_rewrite_hook_ownership:
    command: chown root:users /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_https_rw.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_https_rw.sh

Apache 来源:How to force https on elastic beanstalk?

Nginx 来源:https://adamjstevenson.com/tutorials/2017/02/02/configuring-and-forcing-https-for-aws-elastic-beanstalk.html

<小时/>

两台服务器似乎都存在一些问题但是我无法访问 apache 日志,因为它们没有出现在我的 CloudWatch 中。

但是这是我观察到的行为以及来自 nginx 服务器的日志:

1) 转到:example.xyz:433

Works correctly, browser says we are secure. Nginx log out:

172.31.16.42 - - [16/May/2018:07:54:34 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" "171.6.246.51"

请注意,nginx 的 304 直接设置正在工作

<小时/>

2) 转到:example.xyz

Request spins for ages, eventually times out.

没有注销输出。但是当请求最终超时时,地址栏会填充: https://example.xyz/对我来说,这是重定向正在起作用的另一个迹象。

<小时/>

谁能建议如何解决这个问题?如果您需要更多信息,请告诉我。

干杯

最佳答案

愚蠢地使用了 433 而不是 443。这一切都解决了。感谢@Evyatar Meged 指出这一点。

关于node.js - 我必须包括 :433 to access HTTPS on AWS Elastic Beanstalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50365974/

相关文章:

node.js - 如何使用 nginx 设置 SSL Node.js 应用服务器

https - Apache 2.4 的 ssl 配置不起作用

testing - 认证测试服务器

node.js - 如何将字符串值从exec库返回到对象数组

javascript - nodejs获取请求回调多次命中

node.js - NET Node.js错误: read ECONNRESET (on Windows)

php - 重建后文件更改未反射(reflect)在Docker镜像中

jQuery ajax 不会发出 HTTPS 请求

javascript - 使用异步在 Node JS 中一个接一个地下载视频?

html - 样式表在 nginx 虚拟机中不起作用