Suppose I have many websites with different domain names, domain1.com
, domain2.com
, etc. I have setup the correct virtualhosts configuration for these sites in wildfly. The correct DNS entries are also in place. How do I route requests to my server for these domains to wildfly?
-
Do I simply run wildfly on ports 80 and 443? Something tells me this is a bad idea as wildfly does not run on these ports by default. To run wildfly on those ports require binding to those ports as a privileged user and then switching to an unprivileged user. The hassle and difficulty of doing this suggests that this isn't right.
-
Do I run wildfly behind nginx or apache2? My app spins up websites and virtualhost config dynamically. Can I just forward all requests to wildfly and let it deal with it?
-
???
Best Answer
Option 1 is possible, but as you correctly predicted it is not a preferred approach. In order to run on port 80 or 443, you need a privileged user and you are directly exposing the java server to the public, making it easier to get into trouble.
So fire up nginx, define the domains there and configure
upstream
andproxy_pass
for reverse proxy to your wildfly instances. You get loadbalancing for free, you can handle ssl on nginx instead of wildfly and the whole setup is just so much easier to maintain and scale. You can either setup dedicated wildfly cluster for each domain and have a separateupstream
definition, or you can start with a single instance with separate webcontexts e.g.You can find more info on nginx website