开发者

Play! server: listen to single domain name

I'm trying to get the Play! server listen to a single domain name instead of all domain names that are configured for this server.

I.E. I have two web-services running on two different domain names: example1.com example2.com

Example 1 is running on port 9000, Example 2 is running on port 9001. Port 80 of the respective domains is forwarded to the port in question.

But example 2 is still accessible by example1.com:9001 and I'd like to know how to configure the Play! server in such a way that it will only listen to a specified domain name.

I could fix it in-application by checking the request.host开发者_JS百科 variable but Play! is meant to be easy so I'm looking for the easy solution!

Kind regards, Jan

PS I tried using the http.address configuration parameter but the application still listens to both domain names.


The simple answer to this is to front the Play server with Apache, Nginx, Lighttp or other HTTP server. Configure this http server to act as a reverse proxy for your Play application server, so that example1.com:80 routes to port 9000 and example2:80 routes to port 9001.

Take a look at the following guide, for a clear details of what you need to do. It actually shows two different domains being handled, similar to your requirements.

http://www.playframework.org/documentation/1.2.1/production#server


What you are looking for is a Virtual Host module. There is one available, VHost, but I haven't tried it myself and I don't know if it's compatible with the latest version of Play Framework (1.2.2).

play-vhost module adds ability to write applications which can serve content based on HTTP/1.1 Host header field. Separate data source is maintained for each virtual host.


There is no other way unless you have distinct IP addresses for both hosts. If you don't, you have to examine the host request header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜