virtualhost – Reverse DNS and Apache virtual host

In short: Apache’s VirtualHost doesn’t work as intended when the reverse DNS is enabled.

I’m managing a web service on a single CentOS server. It has a single IP address and multiple subdomains, and each subdomain has a different webroot setting by Apache’s VirtualHost configuration. The *.conf file is located under /etc/httpd/conf.d.

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName any
    DocumentRoot /var/www/html
    # other configurations such as SSLCertificateFile, etc...
</VirtualHost>

<VirtualHost *:443>
    ServerName main-domain.com
    DocumentRoot /home/main-service/front
    # other configurations such as SSLCertificateFile, etc...
</VirtualHost>

<VirtualHost *:443>
    ServerName admin-domain.com
    DocumentRoot /home/main-service/admin
    # other configurations such as SSLCertificateFile, etc...
</VirtualHost>

# and so on...

The objective of this is to control incoming access like this:

  • access via IP address => /var/www/html (returns a simple text that says there is nothing)
  • access via main-domain.com => /home/main-service/front
  • access via admin-domain.com => /home/main-service/admin

Simple enough.

It had been working without any problem until I enable reverse DNS of this IP address to reduce the risk of treated as spam when the system sends emails. After the reverse DNS was enabled for the IP address and main-domain.com, access via main-domain.com is not referred to ServerName main-domain.com section anymore, and Apache refers to the default /etc/httpd/conf.d/ssl.conf file.

I guess some configuration’s priority issue here, but I couldn’t find any document explaining clearly about this. How can I make it work with the reverse DNS enabled?

Apache version is 2.2.