Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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>
share|improve this question
add comment

2 Answers

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
...
share|improve this answer
    
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 .. <VirtualHost *:8088> DocumentRoot "/path/to/site2/" ServerName *:8088 </VirtualHost> –  Ganaiwali Jul 25 '12 at 9: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 9:31
    
wait, did he just say ServerName *:8088 ? –  w00t Jul 25 '12 at 10:05
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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