I am using nginx to serve static content and proxy requests to Apache for serving Django. I have multiple domains, and each domain has it's own port and Apache VirtualHost config. For example, domain1.com proxy_pass to, domain2.com proxy_pass to, etc.

I removed NameVirtualHost and Listen from ports.conf. Any reason why I would need those in there? Seems like Listen for each domain's VirtualHost does the trick.


You won't need them now that you have them defined in the VirtualHost config. The server will always default to the standard port if it is not defined in the config, so you will not have to worry if you remove the VHosts at a later time.

  • I guess where I'm getting tripped up is the docs seem to say that I need to specify a NameVirtualHost for each VirtualHost? I'm not doing that, and it's working, but should I also have a NameVirtualHost for each one? NameVirtualHost NameVirtualHost # etc. <VirtualHost> # ... </VirtualHost> <VirtualHost> # ... </VirtualHost> # etc. – Micah Dec 9 '11 at 1:31

You need one NameVirtualHost per criteria, it tells Apache how it will triage incoming requests. If you want name-based virtual hosting on port 80, you only need

NameVirtualHost *:80

Any HTTP client connecting on port 80 will be triaged along the 'Name:' HTTP header, matching a ServerName or ServerAlias in on of the <VirtualHost *:80> nodes (or the first defined vhost for the same critera if not match is found).

Most of the time you only need two name-based virtual hosting rules : on for port 80, on for port 443 (the latter only really making sense with SNI / Server Name Indication). This is usually done in an automatic manner where the port 443 and *:433 named-based virtual hosting is activated if mod_ssl is activated :

NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
    NameVirtualHost *:443
    Listen 443

In your case, it seems you relyon the usual IP/port-based virtual hosting. In this case every app will need the same code:

Listen 800x
<VirtualHost *:800x>
    ServerName app1

And here the NameVirtualHost is not needed since you only have one virtual host per port. The

is also mostly irrelevant, it will be used by Apache to refer to the vhost in errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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