0

我有一个专门作为网站管理区域前端的微服务。微服务有专门的路由,/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

4

1 回答 1

1

以上ListenerRule匹配管理文件夹中的文件(例如:- 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
于 2019-01-01T05:04:29.537 回答