如何允许用户在不需要端口的情况下访问某些 url

How to allow a user to access some url without requiring the port

我觉得这是一个基本问题,但我正在努力在我的研究中找到任何具体的东西。这一定是一个常见问题,我不确定 google。

我是 运行 一个气隙式 Kubernetes 集群,有一堆服务,每个服务都有 UI。我的服务是使用 NodePort 公开的。我可以通过 ip addr:NodePort 导航到 ui。我使用 dnsmasq 设置了 DNS,因此我可以在 example.domain.com:NodePort.

访问 URL

我想要 "hide" url 的节点端口部分,以便 users/clients 可以访问位于 example.domain.com/appname 的应用程序。

我 运行 一个 Apache 网络服务器来提供一些文件,我已经实现了一堆重定向,例如

永久重定向 /appname http://example.domain.com:30000/

当通过 firefox 浏览器访问 UI 时,它工作得很好,例如example.domain.com/appname。这确实改变了用户地址栏中的 URL,但我可以接受。这样做的问题是一些客户端不会自动重定向到 http://example.domain.com:30000/ 而只是显示 301 状态代码。

有人能给我指出正确的方向吗?

谢谢

您必须将 HTTP 流量从端口 80(标准端口)重定向到您的 NodePort。

例如

sudo iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 30000

使用 apache 或 nginx ,您可以只使用隐藏内部端口的虚拟服务器。我认为您不需要进行任何重定向,您只需要从虚拟服务器 :80 whos 后端向外部客户端提供 url,上游节点是您的内部节点,带有节点端口。

您可以找到 nginx 、 ha-proxy 和其他的简单且更好的示例。

这是一个 Apache 示例:

<VirtualHost *:80>
        ProxyRequests off

        ServerName domain.com

        <Proxy balancer://mycluster>
                # WebHead1
                BalancerMember http://node:NodePort
                # WebHead2
                BalancerMember http://node:NodePort

                # Security "technically we aren't blocking
                # anyone but this is the place to make
                # those changes.
                Require all granted
                # In this example all requests are allowed.

                # Load Balancer Settings
                # We will be configuring a simple Round
                # Robin style load balancer.  This means
                # that all webheads take an equal share of
                # of the load.
                ProxySet lbmethod=byrequests

        </Proxy>

        # balancer-manager
        # This tool is built into the mod_proxy_balancer
        # module and will allow you to do some simple
        # modifications to the balanced group via a gui
        # web interface.
        <Location /balancer-manager>
                SetHandler balancer-manager

                # I recommend locking this one down to your
                # your office
                Require host example.org

        </Location>

        # Point of Balance
        # This setting will allow to explicitly name the
        # the location in the site that we want to be
        # balanced, in this example we will balance "/"
        # or everything in the site.
        ProxyPass /balancer-manager !
        ProxyPass / balancer://mycluster/

</VirtualHost>

看到 Ijaz 的回答后,我可以稍微优化 google 搜索并得出以下结果:

/etc/hosts

192.168.100.1 example.domain.com gitlab.domain.com example
<VirtualHost *:80>
  ServerName gitlab.domain.com
  ProxyPass / http://example.domain.com:30100/
  ProxyReversePass / http://example.domain.com:30100/
</VirtualHost>

systemctl restart httpd dnsmasq

如果您导航到 gitlab.domain.com,您将被重定向到正确的端口 (30100)。

缺点是我部署的每个应用程序都必须有一个域名。我宁愿做类似的事情:

/etc/hosts

192.168.100.1 example.domain.com example
<VirtualHost *:80>
  ServerName example.domain.com
  ProxyPass /gitlab http://example.domain.com:30100/
  ProxyReversePass /gitlab http://example.domain.com:30100/

  ProxyPass /jira http://example.domain.com:30111/
  ProxyReversePass /jira http://example.domain.com:30111/
</VirtualHost>

然而,当我导航到 example.domain.com/gitlab 时,它会附加正确的 url,例如gitlab 的登陆页面是 /users/sign_in, example.domain.com/users/sign_in 但是我的浏览器显示 Not Found。在服务器上找不到请求 URL /users/sign_in。

我想不出正确的配置。如果有人有任何进一步的想法来解决这个问题,请告诉我。