0

Is it possible to create multiple vhosts in Apache pointing the same local network IP?

For example: My machine has local address: 192.168.1.12

Can I have two vhosts pointing the same address but different ports:

  • 192.168.1.12:1 local website 1,
  • 192.168.1.12:2 local website 2.

    ServerName test ServerAlias test DocumentRoot "${INSTALL_DIR}/www/test" Options +Indexes +Includes +FollowSymLinks +MultiViews DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all Require local

If I set just one vhost without fixing the port it works. Example: 192.168.1.12.

If I try to access 192.168.1.12:1 or 192.168.1.12:2, I cannot access the server.

This is my httpd.conf: https://pastebin.com/t5NuF4WJ

  • What you describe is a very common configuration. – Ramhound Nov 27 '17 at 18:29
  • Yes. And you can even listen on the same port, if they have different ServerName. – shinjijai Nov 27 '17 at 18:29
  • I tried but it is not working. I am able to do it just on my machine. If I try to access the server from another machine of the network is not working. – peppe Nov 27 '17 at 18:33
  • what url are you using from the other machines? – Frank Thomas Nov 27 '17 at 18:35
  • 1
    Post the relevant information from your configuration file. – Ramhound Nov 27 '17 at 18:37
0

Assuming you have a SOHO router what you are proposing won't work, but there is a solution.

The issue you will come across is that you are trying to bind multiple IP addresses to a single machine, and have different websites on each. There is no problem doing this - however your SOHO router will probably only be able to map 1 IP address on port 80.

The solution is to have multiple websites on the same internal IP address - and this is a common configuration, and has been supported since RFC2068 in 1997. The way this works is that all the websites point to the same IP address, and the first thing they do when they connect is advise what domain name they wanted. This is called Name Based Virtual hosting.

To do this in Apache you need the following directives:

Ensure the directive "NameVirtualHost X.X.X.X" is in your apache configuration file - this is the internal IP address that the webserver is running on.

Then, for each website, set up a virtualhost folder like

<VirtualHost *:80>
ServerName www.domain.name.of.website
ServerAlias domain.name.of.website alt.domain.name.of.website
DocumentRoot /path/to/website/document/root/

(Other directives specific to site here)
</VirtualHost>

Note that the ServerAlias directive is optional.

Also note that you can do a similar thing with HTTPS hosting on port 443, but needs to specify certificate keys etc as well, and this will only work for newer (Windows 7 and above) systems.

  • The configuration files you provided on Pastebin don't look complete, and are missing the directives above. I expect you may have virtual host configuration file in the conf/extra/httpd-vhosts.conf file - but check you have the NameVirtualHost directive (and provide the httpd-vhosts.conf file – davidgo Nov 27 '17 at 20:17

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.