Javascript 如何使用proxy\u pass重写uringinx反向代理?

Javascript 如何使用proxy\u pass重写uringinx反向代理?,javascript,nginx,proxy,rabbitmq,kubernetes,Javascript,Nginx,Proxy,Rabbitmq,Kubernetes,我正在尝试使用nginx将代理反转为运行各种web应用程序的kubernetes吊舱。我的问题是,我只能在位置设置为/时代理,而不能在/someplace 我知道内部IP正在工作,因为当我使用location/时,两个web应用程序都成功加载,并且我可以在内部卷曲网页 我希望发生什么 前往 前往 通过这种方式,我可以轻松地在同一端口上运行我的所有应用程序 我所相信的正在发生 -->httpL//Pod1IP:3000/app1 我试图通过重写URI来解决这个问题,如下所示,当我试图访问/app1

我正在尝试使用nginx将代理反转为运行各种web应用程序的kubernetes吊舱。我的问题是,我只能在位置设置为
/
时代理,而不能在
/someplace

我知道内部IP正在工作,因为当我使用
location/
时,两个web应用程序都成功加载,并且我可以在内部卷曲网页

我希望发生什么

前往 前往

通过这种方式,我可以轻松地在同一端口上运行我的所有应用程序

我所相信的正在发生 -->httpL//Pod1IP:3000/app1

我试图通过重写URI来解决这个问题,如下所示,当我试图访问
/app1

server {
listen 80;

location = /app1/ {
  rewrite ^.*$ / break;
  proxy_pass http://10.82.5.80:80;
  }
location / {
  proxy_pass http://10.106.228.213:15672;
  }
}
知道我在哪里搞砸了吗

我尝试使用的webapp称为RabbitMQ UI。为了尝试和调试我的情况,我卷曲了三个不同的URL以查看nginx的响应

卷曲
/
加载正确的html页面,并在浏览器中工作

curlhttp://10.82.5.80/

<!doctype html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<html>
  <head>
    <title>RabbitMQ Management</title>
    <script src="js/ejs-1.0.min.js" type="text/javascript"></script>
    <script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"></script>
    <script src="js/sammy-0.7.6.min.js" type="text/javascript"></script>
    <script src="js/json2-2016.10.28.js" type="text/javascript"></script>
    <script src="js/base64.js" type="text/javascript"></script>
    <script src="js/global.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script src="js/prefs.js" type="text/javascript"></script>
    <script src="js/formatters.js" type="text/javascript"></script>
    <script src="js/charts.js" type="text/javascript"></script>

    <link href="css/main.css" rel="stylesheet" type="text/css"/>
    <link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>

<!--[if lte IE 8]>
    <script src="js/excanvas.min.js" type="text/javascript"></script>
    <link href="css/evil.css" rel="stylesheet" type="text/css"/>
<![endif]-->
  </head>
  <body>
    <div id="outer"></div>
    <div id="debug"></div>
    <div id="scratch"></div>
  </body>
</html>
卷曲
/rabbitmq/
位置会生成正确的页面,但会在浏览器中加载空白。我认为这是因为浏览器无法引用html文档中的js文件

卷曲


RabbitMQ管理

尝试在代理位置添加URL,如下所示:

location = /app1/ {
  proxy_pass http://10.82.5:80/;
}
在代理传递的末尾添加一个尾随的
/
,将迫使nginx在将
/app1
前缀发送到后端时从您的请求中删除该前缀

在官方nginx页面上解释其工作原理:


这不是你要代理的地址吗?我是从你的问题中得到的是的,我明白了,但是你能澄清一下删除url重写将如何解决我的问题吗<代码>位置=/app1/{rewrite^.*$/break;代理\u passhttp://10.82.5.80:80}对不起,我忘了提到我的代码片段的意思。更新了我的答案
<!doctype html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<html>
  <head>
    <title>RabbitMQ Management</title>
    <script src="js/ejs-1.0.min.js" type="text/javascript"></script>
    <script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="js/jquery.flot-0.8.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.flot-0.8.1.time.min.js" type="text/javascript"></script>
    <script src="js/sammy-0.7.6.min.js" type="text/javascript"></script>
    <script src="js/json2-2016.10.28.js" type="text/javascript"></script>
    <script src="js/base64.js" type="text/javascript"></script>
    <script src="js/global.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script src="js/prefs.js" type="text/javascript"></script>
    <script src="js/formatters.js" type="text/javascript"></script>
    <script src="js/charts.js" type="text/javascript"></script>

    <link href="css/main.css" rel="stylesheet" type="text/css"/>
    <link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>

<!--[if lte IE 8]>
    <script src="js/excanvas.min.js" type="text/javascript"></script>
    <link href="css/evil.css" rel="stylesheet" type="text/css"/>
<![endif]-->
  </head>
  <body>
    <div id="outer"></div>
    <div id="debug"></div>
    <div id="scratch"></div>
  </body>
</html>
location = /app1/ {
  proxy_pass http://10.82.5:80/;
}
If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive: