Apache multiple virtual hosts on the same same ip(diffrent url's)

Jonathan picture Jonathan · Oct 5, 2011 · Viewed 13.9k times · Source

I have 2 virtual hosts(bugzilla and board review) on an apache server sitting inside an ubuntu machine.

I have one external ip address I can use(with one port enabled) so I can't assign different host names or different ports for the virtual hosts.(correct me if I'm wrong)

I want the user to be able to write the following: http://ip-address:port/bugzilla and for the requests to go to bugzilla and for requests from http://ip-address:port/review to go to the review board.

I tried reverse proxying from the first vhost to the second but that didn't work.

The bugzilla conf file uses cgi and the review board uses wsgi.

Is there a simple way of accomplishing the above?

Thanks in advance.

Answer

Eduardo Dennis picture Eduardo Dennis · Sep 26, 2014

You can achieve this using the Alias directive.

The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path. The URL-path is case-sensitive, even on case-insensitive file systems.

Alias "/image" "/ftp/pub/image" A request for http://example.com/image/foo.gif would cause the server to return the file /ftp/pub/image/foo.gif. Only complete path segments are matched, so the above alias would not match a request for http://example.com/imagefoo.gif. For more complex matching using regular expressions, see the AliasMatch directive.

Your Virtual host file would look like this

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName ip-address:port/bugzilla 
    Alias "/bugz" "var/www/html/bugz"
    Alias "/wow" "var/www/html/wow"    
    DocumentRoot /path/to/yourwebsite  
</VirtualHost>

Achieving your goal of having multiple virtual hosts on the same IP.

GIF of it working

enter image description here

NOTE

  • This is working for Apache 2.4.18
  • The GIF shows a VirtualHost configuration with two different virtual host entries. One of the comments to this answer said different virtual hosts don't work. But they do, as long as the server name is different.