I have a DirectAdmin setup with Apache on a server which is behind NAT.

Everything is working correctly when accessing a VirtualHost from outside the machine (either through the Internet and the Intranet) but I'm having problems when accessing the very same VirtualHost from the localhost (i.e. by using curl mywebsite.com inside the server).

Relevant network devices:

eth0   : IP Address inside the NAT
eth0:0 : IP Address outside the NAT (i.e. public IP Address)
eth1   : LAN IP Address
lo     : Loopback

Below is the relevant httpd configuration:

Listen 80
NameVirtualHost *:80

DocumentRoot "/var/www/html"

<VirtualHost *:80>
  ServerName mydomain.com

When using a wildcarded NameVirtualHostone would expect a request with the Host: mydomain.com directive set in the request header (which curl does) to be served by the VirtualHost directive. Although, when I curl mydomain.com from inside the server, Apache fallback to the DocumentRoot not allowing me to access the VirualHost host.

The only way I got it to work was to edit /etc/hosts and define the IP inside the NAT for mydomain.com.

Another piece of information that may be useful:

I ran <?php print_r($_SERVER); ?> on a test page both from inside and outside the server to check the values for SERVER_IP and when I curl from a remote machine I get the IP address inside the NAT, but when I curl from inside the server I get the public IP address.

The domain resolves to the very same IP address on both ends (inside and outside the server).

Best Regards.

2 Answers 2


You can use http://xip.io to define a temporary domain for your virtual host using your computer's IP address.

Simple and easy ;)

  • I don't think this is a good answer, nor does your link work
    – gstlouis
    May 11, 2022 at 13:44

you might want to look into this post from me to see if it is relevant

reaching an apache reverse proxy virtualhost from localhost behind a NAT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.