0

Is there a way to host apache multiple name based virtual hosts on different ports on single apache instance ?

Say for example default instance listen on port 80

Listen 80
<VirtualHost *:80>
    ServerAdmin alert@example.com
    DocumentRoot /usr/local/apache/htdocs/example
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / http://www.example.com/
    ErrorLog logs/error_log
    CustomLog logs/access_log combined
</VirtualHost>

now I would like to have on the same instance of apache

<VirtualHost *:8088>
    ServerAdmin alert@example.com
    DocumentRoot /usr/local/apache/htdocs/example1
    ServerName example1.com
    ServerAlias www.example1.com
    Redirect permanent / http://www.example1.com/
    ErrorLog logs/error_log
    CustomLog logs/access_log combined
</VirtualHost>
Khaled
  • 36,533
  • 8
  • 72
  • 99
Ganaiwali
  • 3
  • 3

2 Answers2

2

You will also need to tell Apache itself to listen on the extra ports in /etc/apache2/ports.conf (if you're on a RedHat-based distro, it'll be in /etc/httpd/)

...
NameVirtualHost *:81
NameVirtualHost *:85
Listen 81
Listen 85
...
poolski
  • 124
  • 1
  • 3
  • 10
  • thanks for the reply , i got this working by specifying Listen / NameVirtualHost in the same httpd.conf however still can't get to the virtual hostname , i even tried .. DocumentRoot "/path/to/site2/" ServerName *:8088 – Ganaiwali Jul 25 '12 at 09:12
  • I would recommend using separate vhost configs instead of lumping everything in to httpd.conf. /etc/apache2/sites-available/example.com /etc/apache2/sites-available/example1.com then either symlink them to /etc/apache2/sites-enabled/ or run _a2ensite example1.com example2.com_ Did you add the ports into ports.conf? Also, check Apache2 is listening on 8088 by running _lsof -i :8088_ – poolski Jul 25 '12 at 09:31
  • wait, did he just say ServerName *:8088 ? – w00t Jul 25 '12 at 10:05
1

Yes. Specify the port in both the NameVirtualHost directive and in the <VirtualHost> directive.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84