AWS ALB路由-找不到请求的网址

时间:2019-01-01 04:24:48

标签: amazon-web-services aws-application-load-balancer

我有一个微服务,专门用作网站管理区域的前端。微服务有一条专用于它的路由,/admin。当我尝试访问时,这给了我404 error。下面给出的是微服务云模板的摘录。

Resources:
  Service:
    Type: AWS::ECS::Service
    DependsOn: ListenerRule
    Properties:
      Cluster: !Ref Cluster
      Role: !Ref ServiceRole
      DesiredCount: !Ref DesiredCount
      TaskDefinition: !Ref TaskDefinition
      LoadBalancers:
        - ContainerName: "activity-monitor-service"
          ContainerPort: 80
          TargetGroupArn: !Ref TargetGroup

  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Family: activity-monitor-service
      ContainerDefinitions:
        - Name: activity-monitor-service
          Essential: true
          Image: registry.hub.docker.com/abameerdeen/activity_monitor:v4
          Memory: 128
          Environment:
            - Name: PRODUCT_SERVICE_URL
              Value: !Ref ProductServiceUrl
          PortMappings:
            - ContainerPort: 80
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref CloudWatchLogsGroup
              awslogs-region: !Ref AWS::Region

  CloudWatchLogsGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Ref AWS::StackName
      RetentionInDays: 365

  TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      VpcId: !Ref VPC
      Port: 80
      Protocol: HTTP
      Matcher:
        HttpCode: 200-299
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: /test.html
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 5
      HealthyThresholdCount: 2

  ListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      ListenerArn: !Ref Listener
      Priority: 2
      Conditions:
        - Field: path-pattern
          Values: [ "/admin/*" ]
      Actions:
        - TargetGroupArn: !Ref TargetGroup
          Type: forward

我在基础架构中也有一个应用程序负载平衡器(ALB)。这是我的项目:https://github.com/ammarisme/aws-cloudformation.git

1 个答案:

答案 0 :(得分:1)

ListenerRule上的文件与admin文件夹内的文件(例如:-index.html)匹配,而不与路径/匹配。因此,我添加了丢失的ListenerRule,如下所示。

ListenerRule2:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      ListenerArn: !Ref Listener
      Priority: 3
      Conditions:
        - Field: path-pattern
          Values: [ "/admin" ]
      Actions:
        - TargetGroupArn: !Ref TargetGroup
          Type: forward