创建AWS Application Load Balancer规则,该规则可修剪请求的前缀,而无需使用其他反向代理,例如nginx,httpd [英] Create AWS Application Load Balancer Rule which trim off request's prefix without using additional reverse proxy like nginx, httpd

查看:199
本文介绍了创建AWS Application Load Balancer规则,该规则可修剪请求的前缀,而无需使用其他反向代理,例如nginx,httpd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有几个服务.我想将每个带有前缀"/安全"的请求转发到server1端口80,并将所有其他请求转发给服务器2的端口80.问题是在server1上,我正在运行接受不带"/安全"前缀的请求的服务.换句话说,我要转发每个请求,例如" http://example.com/secured/api/getUser "作为" http://example.com/api/getUser "(从请求的路径中删除/secured).

Basically, I have a couple of services. I want to forward every requests with prefix "/secured" to server1 port 80 and all other requests to server 2 port 80. The problem is that on server1, I am running service which accept the request without "/secured" prefix. In other words, I want to forward every requests such as "http://example.com/secured/api/getUser" to server1 as "http://example.com/api/getUser" (remove /secured from request' path).

使用AWS ALB,当前请求以 http://example.com/secured/api/发送getUser ;这迫使我更新server1的代码,以便该代码处理带有/secured前缀(看起来不太好)的请求.

With AWS ALB, currently the request is sent as http://example.com/secured/api/getUser; which forces me to update my server1's code so that the code handles requests with /secured prefix which doesn't look good.

有什么简单的方法可以解决ALB问题吗?

Is there any easy way to solve this with ALB?

谢谢.

推荐答案

我遇到了同样的问题,正如Mark指出的那样,您可以在服务器上使用反向代理并执行以下操作(这是Nginx配置):

I had the same issue, and as Mark pointed out, you can use reverse proxy on your server and do something like this (this is Nginx configuration):

server {
  listen 80 default_server;

  location /secured/ {
    proxy_pass http://localhost:{service_port}/;
  }
}

这将剥除/secured部分并将其他所有内容代理到您的服务.只需确保在服务端口后面有/即可.

This will strip the /secured part and proxy everything else to your service. Just be sure to have the trailing / after the service port.

这篇关于创建AWS Application Load Balancer规则,该规则可修剪请求的前缀,而无需使用其他反向代理,例如nginx,httpd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆