Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

apache - NameVirtualHost *:80 has no VirtualHosts

I have two domain names, two ssl certs and two ip addresses. I am trying to configure my apache virtualhost files for them.

First, i commented out all instances of "NameVirtualHost" and "Listen" for ports 80 and 443. Then i did the following with my virtual hosts files.

VirtualHost file for domain1:

NameVirtualHost 1.1.1.1:80
Listen 1.1.1.1:80
Listen 1.1.1.1:443
<VirtualHost 1.1.1.1:80>
    ServerName domain1.com
    ...
</VirtualHost>
<VirtualHost 1.1.1.1:443>
    ...
</VirtualHost>

VirtualHost file for domain2:

NameVirtualHost 2.2.2.2:80
Listen 2.2.2.2:80
Listen 2.2.2.2:443
<VirtualHost 2.2.2.2:80>
    ServerName domain2.com
    ...
</VirtualHost>
<VirtualHost 2.2.2.2:443>
    ...
</VirtualHost>
question from:https://stackoverflow.com/questions/7165655/namevirtualhost-80-has-no-virtualhosts

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Somewhere in your configuration, probably in the Apache default configuration file (I think /etc/apache2/httpd.conf in Ubuntu? someone can correct me in the comments), is a line that looks like:

NameVirtualHost *:80

# Also
Listen 80
Listen 443

Comment them out, and in your VirtualHost configuration files, add:

Listen 111.111.111.111:80
Listen 222.222.222.222:80
# If also using SSL
Listen 111.111.111.111:443
Listen 222.222.222.222:443

NameVirtualHost 111.111.111.111:80
NameVirtualHost 222.222.222.222:80

In many default Apache configurations, the Listen and NameVirtualHost directives are supplied with wildcards, or globally to apply to all network interfaces. Since you're using multiple IP addresses bound to different configurations, you need to be more specific in your config directives than your distribution's default config file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...