我必须包括:433以访问AWS Elastic Beanstalk上的HTTPS

时间:2018-05-16 08:33:13

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

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

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

目前,我只是尝试为EB Load Balancer工作的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和amp;试试这个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

  

正常工作,浏览器说我们很安全。 Nginx退出:

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

  

请求旋转多年,最终超时。

没有退出输出。但是当请求最终超时时,地址栏中会填充:https://example.xyz/这对我来说是另一种指示,重定向正在起作用。

有人可以建议如何解决这个问题吗?如果您需要更多信息,请与我们联系。

干杯

1 个答案:

答案 0 :(得分:0)

愚蠢地使用了433而不是443.这是全部排序。感谢@Evyatar Meged指出它。