How do I create Virtual Hosts for Different Ports on Apache?

Solution 1:

To expand on Jeff's answer you'll need something like this in your apache configuration

Listen 80
Listen 81
Listen 82

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www1
ServerName www.example1.com
</VirtualHost>

NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot /var/www2
ServerName www.example2.org
</VirtualHost>


NameVirtualHost *:82
<VirtualHost *:82>
DocumentRoot /var/www3
ServerName www.example3.org
</VirtualHost>

Solution 2:

Step 1: Configure Apache to Listen on each of the ports you want to service.

Step 2: Set up a Virtual Host configuration for each port you want to service.