I have an existing php/apache httpd server hosting a simple static website. Now we want to add a full webapp using the Play! Java framework without removing the existing static website and server.
Can I use apache to redirect traffic based on url, for instance route all traffic to product.example.com
or www.example.com/product
to the Play! server?
And if so, how do I do this?
I did this as well, and it is quite easy with Apache. Set up VirtualHosts just as you would normally for your static sites, but for your Play host, redirect to a port using Apache mod_proxy
like so:
Make sure to run a2enmod proxy proxy_http
and then set up a proxy host like so:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ProxyPreserveHost On
ServerName product.example.com
ServerAlias www.product.example.com
ProxyPass / http://127.0.0.1:9000/ #incoming requests pass to Play app
ProxyPassReverse / http://127.0.0.1:9000/ #outgoing responses go back to user
</VirtualHost>
This will redirect requests to your domain or subdomain specified to the Play app on the specified port at localhost (or any other host you want). You can add additional VirtualHost directives for your other apps created with different platforms or languages. This is also a great way to load balance Play applications.
If you prefer not to use subdomains, you can use mod_rewrite
on your static site to redirect requests for example.com/product
to the Play framework proxy.
Here is more documentation on the subject: http://www.playframework.com/documentation/2.2.0/HTTPServer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.