要在AWS ELB(Elastic Load Balancer)上重写路径并修改中间路径,可以使用“Path Rewrite”功能。以下是一个代码示例,展示如何通过AWS CLI进行设置:
aws elbv2 create-rule --listener-arn --priority 1 --conditions Field=path-pattern,PathPatternConfig={Values=[/*]} --actions Type=fixed-response,FixedResponseConfig={StatusCode=200,ContentType=text/plain,MessageBody=RewrittenPath} --rule-arn
在此示例中,
是负载均衡器监听器的ARN,
是规则的ARN。
aws elbv2 modify-rule --rule-arn --actions Type=redirect,RedirectConfig={Protocol=HTTPS,Port=443,Host=#{host},Path=/new-path/middle-path,Query=#{query},StatusCode=301}
在此示例中,
是规则的ARN。
通过执行以上两个步骤,您可以成功地在AWS ELB上重写路径并修改中间路径。请确保将
和
替换为您自己的ARN值,并根据需要修改路径和中间路径。