我可以(DNS)将一个子域映射到多个Play Framework入口点

问题描述:

以下情况是否可行?一个警告,我只理解DNS的基本形式。

Is the scenario below possible? A warning that I understand DNS only in its basic form.

我们有一个API(使用 Play ),我们希望通过一个地址提供 http://api.publicname .com

We have an API (built using Play) that we would like to make available via a an address say http://api.publicname.com

但是,我们希望在2个Play项目(例如myapione和myapitwo)中分解此API。
然后只使用1个域,而是两个独立的子文件夹访问它们。

However, we would like to split this API in 2 Play projects (e.g. myapione and myapitwo). Then access them using only 1 domain but two separate "subfolders"

所以我一直在寻找映射的可能性...

So I have been looking for the possibility of mapping say...

http://myinternal.domain:9000 http://api.publicname.com/myapione

。 ..和另一个播放应用程序

... and another Play application

http://myinternal.domain:9001 to http://api.publicname.com/myapitwo

我们正在寻找的最终结果如下所示。
我们会看起来像...

The end result we are looking for is something like below. We would have calls looking like...

http://myinternal.domain:9000 / products / 123 也是 http ://api.publicname.com/myapione/products/123

http://myinternal.domain:9001 / orders / 456 也是 http://api.publicname.com/myapitwo/orders/456

目标:

Public URL              -> maps to -> internal URL
http://api.publicname.com/myapione -> http://localhost:9000
http://api.publicname.com/myapitwo -> http://localhost:9001

正如@applicius所说,由前面或来源HTTP服务器,将请求代理到较低级应用程序或服务HTTP服务器。它不是真的关于虚拟主机。

is achieved, as @applicius said, by a "front-facing" or "origin" HTTP server which proxies the request through to the lower level "application" or "service" HTTP servers. It isn't really about virtual hosts though.

Nginx,Apache等是常见的。我认为nginx是伟大的。做这个并且令人惊奇的商业产品是宙斯或ZXTM。它被买了我认为,所以我不知道如果它仍然可以自己。

Nginx, Apache, etc are common. I think nginx is great. A commercial product which does this and is amazing is Zeus or ZXTM. It was bought out I think so I'm not sure if it's still available on its own.

为上述的nginx配置,例如:

Configuration for nginx for the above, something like:

server {
    listen       80;
    server_name  api.publicname.com/myapione;

    location /myapione {
        proxy_pass        http://localhost:9000;
        proxy_set_header  X-Real-IP  $remote_addr;
    }

    location /myapitwo {
        proxy_pass        http://localhost:9001;
        proxy_set_header  X-Real-IP  $remote_addr;
    }
}

这种方法可以让您拼接在一起尽可能多的服务如您所愿,并以外部来电者的身份出现。例如,要在 static 下面提供静态文件资产,以及在 / 之下的所有未匹配的前端HTML服务器:

This approach lets you "stitch" together as many services as you like and appear as one to external callers. For example, to serve static file assets under static and a front-facing HTML server for everything not matched under /:

    location /static/ {
        alias /app/myapp-pages/static;
    }

    location / {
        proxy_pass        http://localhost:8000;
        proxy_set_header  X-Real-IP  $remote_addr;
    }

有了这个:

Public URL              -> maps to -> internal URL
http://api.publicname.com/myapione -> http://localhost:9000
http://api.publicname.com/myapitwo -> http://localhost:9001
http://api.publicname.com/static   -> local file assets
http://api.publicname.com/...      -> http://localhost:8000

这不执行任何负载平衡,但你可以把某些主机上的其他服务:进行负载平衡的端口,然后点nginx。

This doesn't do any load balancing, but you could put the other services on some host:port that does the load balancing, and then point nginx at it.

ZXTM 产品很有趣,因为它同时执行上述代理和负载平衡。 (我不认可它比任何其他东西,只是我已经看到它在生产中使用,令人印象深刻。)

The ZXTM product is interesting because it does both the above proxying and load balancing. (I'm not endorsing it more than anything else, it's just that I have seen it used in production and it's impressive.)

注意,Play虽然很好,更适合于渲染页面,并提供将呼叫组合到较低HTTP服务的较高级别的API。较低级别的HTTP服务可以使用像DropWizard这样的工具包来编写,它只关注提供非页面的API。

Side note that Play, while excellent, is better suited to rendering pages and providing a higher level API that combines calls to lower HTTP services. Lower-level HTTP services can be written with a toolkit like DropWizard, which focuses only on providing an API not pages.