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

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 127.0.0.1:8000, domain2.com proxy_pass to 127.0.0.2:8010, 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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
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 127.0.0.1:8000 NameVirtualHost 127.0.0.1:8001 # etc. <VirtualHost 127.0.0.1:8000> # ... </VirtualHost> <VirtualHost 127.0.0.1:8001> # ... </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
</IfModule>

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
    [...]
</VirtualHost>

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

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

share|improve this answer

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.