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

For example: My machine has local address:

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

  • local website 1,
  • 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:

If I try to access or, 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, 2017 at 18:29
  • Yes. And you can even listen on the same port, if they have different ServerName.
    – shinjijai
    Nov 27, 2017 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, 2017 at 18:33
  • what url are you using from the other machines? Nov 27, 2017 at 18:35
  • 1
    Post the relevant information from your configuration file.
    – Ramhound
    Nov 27, 2017 at 18:37

1 Answer 1


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)

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, 2017 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .