Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Declare multiple ports for the same VirtualHosts:

SSLStrictSNIVHostCheck off
# Apache setup which will listen for and accept SSL connections on port 443.
Listen 443
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:443

<VirtualHost *:443>
  ServerName domain.localhost
  DocumentRoot "/Users/<my_user_name>/Sites/domain/public"
  <Directory "/Users/<my_user_name>/Sites/domain/public">
    Order allow,deny
    Allow from all

  # SSL Configuration
  SSLEngine on

How can I declare a new port ('listen', ServerName, ...) for 'domain.localhost'?

If I add the following code, apache works (too much) also for all other subdomain of 'domain.localhost' (subdomain1.domain.localhost, subdomain2.domain.localhost, ...):

<VirtualHost *:80>
  ServerName pjtmain.localhost:80
  DocumentRoot "/Users/Toto85/Sites/pjtmain/public"
  RackEnv development
  <Directory "/Users/Toto85/Sites/pjtmain/public">
    Order allow,deny
    Allow from all
share|improve this question
Just to note. You cant join https and non-https virtual host into one. <VirtualHost *:80 *:443>. 80 Cannot have "SSLEngine on". You have to have 2 sepearate VirtualHost declarations for SSL and non-SSL. – Gacek May 10 '14 at 12:57
up vote 29 down vote accepted

The question is somewhat ambiguous, but I'll try to help.

If you want the same virtualhost to listen on multiple ports, then you do this:

Listen 80
NameVirtualHost *:80

Listen 8080    
NameVirtualHost *:8080

<VirtualHost *:80 *:8080>

Generally speaking you don't define multiple name-based VirtualHosts of the same domain name, unless you need to use a different protocol.

For SSL name-based virtualhosts you have to be extra careful: by definition there can not be multiple certificates on the same IP:Port, so, to avoid certificate errors it would have to be a wilcard certificate, covering all served domain names.

share|improve this answer
+1 but some small correction: SSL certificates are not tied to IP adresses but to common names (CN) which must equal the host name. Also with the SNI extension it is possible to have multiple virtual hosts with different certificates on the same IP address. ( – Daniel Rikowski Mar 11 '13 at 14:55
+1 too, for SSL it should be <VirtualHost *:80 *:443> – fedmich Jun 10 '14 at 23:10

Your Answer


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.