首页 > 解决方案 > 如何从烧瓶应用程序获取请求 url?

问题描述

我在服务器上有一个烧瓶应用程序。该烧瓶应用程序使用该代码启动。

app.run(host="0.0.0.0",debug=True, port=3001,threaded=True)

当我尝试使用服务器公共 IP 访问该应用程序时。我可以获得完整的标题。我得到带有dict(request.headers).

在我的 dockerhost 上,我有 30 个容器,它们看起来与烧瓶应用程序的地址相同。我的意思是;

public-ip:3001/test 和 my.sites.example.com/test 是那个烧瓶应用程序。如果我调用 public-ip:3001/test 我将我的公共 ip 作为主机。当我调用 my.sites.example.com/test 时,我得到 0.0.0.0:3001/test 作为主机。我正在尝试获取 my.sites.example.com。

我的 nginx 设置是;对于码头集装箱:

  location /test/ {
    proxy_pass  http://0.0.0.0:3001/test/;
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
  }

对于服务器:

 location / {
      proxy_pass  http://127.0.0.1:3001/;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
  }

我的主要目标是获取客户的请求网址。public-ip:3001/test 和 my.sites.example.com/test 是那个烧瓶应用程序。如果我调用 public-ip:3001/test 我将我的公共 ip 作为主机。当我调用 my.sites.example.com/test 时,我得到 0.0.0.0:3001/test 作为主机。我正在尝试获取 my.sites.example.com。

标签: pythonflaskrequest

解决方案


推荐阅读