【问题标题】:Apache2 - Subdomain to port -> forwardingApache2 - 子域到端口 -> 转发
【发布时间】:2012-08-07 02:09:52
【问题描述】:

好的,由于阅读了数百本手册和说明页,但我仍然没有理解,我正处于某个时刻,我觉得自己非常愚蠢。我希望你能帮助我!

我有一台运行 Ubuntu Server 的服务器。在服务器上,我正在运行 ddclient 以使用 dyn.com 更新我的 IP。我有一个域“rasterkomplex.net”,它指向更新的 IP。很简单。

还有一个摄像头连接到服务器,运行它自己的网络服务器@端口 3360。

当我现在进入时:rasterkomplex.net:3360 - 瞧。 但是现在有 2 个 minecraft 服务器同时在 5001 和 5002 上运行。对于每个 mc-server,都有 dynmap-plugins 也在不同的端口上运行一个 webserver。然后是一个网络存储……你明白了吗?我不想记住8个或更多端口,只是为了访问相关服务。

我想要完成的事情:

cam.rasterwerks.net -> internal to 127.0.0.1:3360
mc1.rasterwerks.net -> internal to 127.0.0.1:5001
mc2.rasterwerks.net -> internal to 127.0.0.2:5002
etc. etc. etc.

我阅读了很多关于 VHosts、ProxyPass 等的信息。但我无法管理它来工作。

你能给我一个方向吗?如果它与虚拟主机有关,也许是一个示例?

非常感谢您的宝贵时间!

问候,

埃利亚斯。

【问题讨论】:

    标签: apache ubuntu subdomain portforwarding dyndns


    【解决方案1】:

    您可以使用apache 来做到这一点,一方面ProxyPass 或mod_proxy 将您重定向到这里或那里,或者您也可以安装haproxy。然后,根据请求的 URL 中的主机将请求传递到一个或另一个网络存储。

    haproxy 的示例配置正是这样做的:

    frontend public
    bind        X.X.X.X:80
    mode        http
    log         global
    option      httplog
    option      dontlognull
    option      httpclose
    maxconn     8000
    clitimeout  90000
    
    reqisetbe   ^Host:\ .*hudson    hudson
    
    backend hudson
        mode            http
        balance         roundrobin
        contimeout      120000
        srvtimeout      120000
        redispatch
        retries         5
        server          internal.host.com Y.Y.Y.Y:8080 check inter 1000
    

    所以在本例中,haproxy 绑定到端口 80,当请求的 URL 包含 *.hudson 时,它会被重定向到 IP 为 Y.Y.Y.Y 的 internal.host.com 到端口 8080。

    现在,对于基于 apache 的解决方案。

    您可以定义多个具有不同名称的虚拟主机,每个虚拟主机都包含以下内容。

    要进行基于名称的虚拟主机,您的 apache 配置应包含:

    NameVirtualHost *
    

    那么,虚拟主机本身应该是:

    <Virtualhost *>
      DocumentRoot "/var/www/somewhere"
      ServerName localhost
      ServerAdmin support@mycompany.com
      DirectoryIndex index.html index.php
      ProxyRequests On
      ProxyPreserveHost On
      ProxyVia full
    
      <proxy>
        Order deny,allow
        Allow from all
      </proxy>
    
      ProxyPass        /  http://somehost:1234/
      ProxyPassReverse /  http://somehost:1234/
    </Virtualhost>
    

    随意选择对您来说更可行的解决方案。

    【讨论】:

    • 我使用了 VHost 解决方案,它的工作原理非常棒——除了请求不是来自端口 80 的尝试,比如当我尝试使用 ssh、游戏或 rtsp 时。但我想那是因为 apache2 只是一个网络服务器?那还能怎么实现呢?有了这个 haproxy 的东西?无论如何,非常感谢!
    • 是的,apache 只是网络服务器。另一方面,haproxy 是一种支持 TCP 的负载均衡器。
    猜你喜欢
    • 1970-01-01
    • 2013-08-28
    • 2023-01-18
    • 1970-01-01
    • 2017-12-28
    • 2016-04-06
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多