0

Is it possible to have two virtual host configurations for the same server - one with internal ip address and one with domain name(the domain name points to the same server with the internal ip address)? Something like

Example for a server A the domain name is a.com, internal IP is xxx.xxx.xxx.xxx and external ip is yyy.yyy.yyy.yyy. The document root is also the same for them /var/www/html

 <VirtualHost xxx.xxx.xxx.xxx:80>
 .......
 </VirtualHost>


  <VirtualHost a.com:80>
  .......
  </VirtualHost>

Note that the internal IP address and the domain name belong to the same server or same server instance.

I am asking this to restrict some URLs for external users, redirect to https all external access and allow everything for internal users(without https).

Also they are for the same application...

1

Is it possible to have two virtual host configurations for the same server - one with internal ip address and one with domain name?

Yes it is possible.

I would recommend you read through the Vhost Documentation

0

Yes it is possible. You will have to create two vhost configuration files with both of them pointing to the same document root.

Lets say you use Centos, your apache configuration files are available in /etc/httpd/conf/custom/

You will have to create two configuration files, one for the external domain and the other for your internal ip as follows

$ nano /etc/httpd/conf/custom/namevirtualhost.conf
$ nano /etc/httpd/conf/custom/a.com.conf

Putting each virtual host in its own file will make it easier to edit, enable, or disable them in the future.

In each of these files change the following line as appropriate NameVirtualHost *:80

The document root in both these files should point to the same directory DocumentRoot /home/your home directory/public_html/domain1.com/public

You might want to have separate access logs, one for the domain and one for the internal ip in which case

ErrorLog /var/log/httpd/domain1.com/log/error.log
CustomLog /var/log/httpd/domain1.com/log/access.log combined

Restart Apache and you are set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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