How do you configure Floating IP and Virtualmin properly so each virtual host is loaded correctly?

March 31, 2018 456 views
Initial Server Setup Networking PHP Server Optimization CentOS

I'm using CentOS 6.9 with Virtualmin installed as my app server.
The server also has PHP installed.
It serves multiple virtual hosts.
It's been working well for the past 2 years.

I'm trying to use Floating IP.
I already followed the guides from DigitalOcean and the floating ip already points to proper anchor ip and works well.
However, it keeps loading the default documentroot from httpd.conf and it doesn't even load PHP files now.

I already made sure that all the IP addresses in "ip addr sh" match those in "grep -i '<virtualhost' /etc/httpd/conf/httpd.conf".

Am I missing something?

Any help is appreciated.
Thanks.

3 Answers

Sorry you're having trouble. One thing to keep in mind when working with floating IPs is that your droplet will never see the public floating IP used to request it. Your droplet will see all requests for the floating IP coming from the anchor IP and this anchor IP needs to be reflected in your Apache configuration. It sounds like everything is working properly but Apache is not routing the request properly to the correct Virtualhost.

Are all your VirtualHost configurations stored within your main httpd.conf file? On most modern distributions of Apache, virtualhosts are configured in individual files in /etc/httpd/sites-enabled/ - be sure that any hosts that need to listen for requests from the floating IP are listening on your anchor IP.

Hi ryan, thanks for the reply.

Actually, I used anchor IP and it didn't work.
I also tried changing it to floating IP and that didn't work either.

However, I found a workaround by specifying * on port 80 and 443 in addition to the other vhost configuration.
It works fine now.

Thanks.

I set mine to "any" in the Apache Virtual Server for each one, and when I then test by using my hosts file on my computer to point to the floating IP for a virtual server hostname, it then loads correctly and my traceroute shows the proper floating IP to verify too. I think like stevens said, setting it to * (or "any") will do the trick.

I'm personally now looking to see how I can make sure this also works for the mail servers too. I guess that'd just be a simple DNS change though pointing to the floating IP.

Have another answer? Share your knowledge.