我们有一个运行七个域/子域的服务器。 为了尽可能less地尝试,我将包括其中四个。
服务器在90%的时间内都工作得很好,但偶尔我们会得到更多的请求,数据库服务器也会closures。 这然后最大的apache连接,因为所有的数据库连接正在等待超时。 一切顺利,我们强制重新启动数据库,连接恢复。 但是,这些请求将进入dfw.example.comconfiguration。 该部署没有我们的代码库,这是一个大问题,我不明白为什么发生这种情况。 在这种情况发生的时候,它也一直在进行部署,而我们从来没有任何其他的5。
从我读的文档中,我认为Apache通过httpd.conf文件读取并查找第一个NamedVirtualHost匹配:
现在,当请求到达时,服务器将首先检查是否使用了与NameVirtualHost匹配的IP地址。 如果是,那么它将查看每个具有匹配的IP地址的
<VirtualHost>部分,并尝试find一个ServerName或ServerAlias与所请求的主机名相匹配的部分。 如果find一个,那么它使用该服务器的configuration。 如果找不到匹配的虚拟主机,则将使用与IP地址匹配的第一个列出的虚拟主机。
我们正在运行Apache 2.2.15。
我认为与httpd.conf文件相关的部分是:
Listen 80 Listen 255.255.255.255:443
…
ServerName www.example.com
…(这是确切的顺序,www(https / http),dfw,然后所有其他版本)
NameVirtualHost www.example.com:80 <VirtualHost www.example.com:80> ServerAdmin [email protected] DocumentRoot /var/www/html/www.example.com ServerName www.example.com DirectoryIndex index.html DirectoryIndex index.php LogLevel notice ErrorLog /var/log/httpd/www.example.com/error.log CustomLog /var/log/httpd/www.example.com/access.log w3c_extended </VirtualHost> NameVirtualHost www.example.com:443 <VirtualHost www.example.com:443> ServerAdmin [email protected] DocumentRoot /var/www/html/www.example.com ServerName www.example.com #certificate stuff DirectoryIndex index.html DirectoryIndex index.php LogLevel notice ErrorLog /var/log/httpd/www.example.com/error.log CustomLog /var/log/httpd/www.example.com/access.log w3c_extended </VirtualHost> NameVirtualHost dfw.example.com:80 <VirtualHost dfw.example.com:80> ServerAdmin [email protected] DocumentRoot /var/www/html/dfw.example.com ServerName dfw.example.com DirectoryIndex index.html DirectoryIndex index.php LogLevel notice ErrorLog /var/log/httpd/dfw.example.com/error.log CustomLog /var/log/httpd/dfw.example.com/access.log w3c_extended </VirtualHost> NameVirtualHost chris.example.com:443 <VirtualHost chris.example.com:443> ServerAdmin [email protected] DocumentRoot /var/www/html/chris.example.com #cert stuff ServerName chris.example.com DirectoryIndex index.html DirectoryIndex index.php LogLevel notice ErrorLog /var/log/httpd/chris.example.com/error.log CustomLog /var/log/httpd/chris.example.com/access.log w3c_extended </VirtualHost> NameVirtualHost chris.example.com:80 <VirtualHost chris.example.com:80> ServerAdmin [email protected] DocumentRoot /var/www/html/chris.example.com ServerName chris.example.com DirectoryIndex index.html DirectoryIndex index.php LogLevel notice RewriteLog /home/chris/writinglog.log RewriteLogLevel 8 ErrorLog /var/log/httpd/chris.example.com/error.log CustomLog /var/log/httpd/chris.example.com/access.log w3c_extended CheckSpelling on </VirtualHost>
做一个sudo service httpd restart获得正确的部署服务。
apachectl -S输出:
VirtualHost configuration: [IPV6ADDRESS]:443 is a NameVirtualHost default server chris.example.com (/etc/httpd/conf/httpd.conf:1077) port 443 namevhost chris.example.com (/etc/httpd/conf/httpd.conf:1077) [IPV6ADDRESS]:80 is a NameVirtualHost default server chris.example.com (/etc/httpd/conf/httpd.conf:1095) port 80 namevhost chris.example.com (/etc/httpd/conf/httpd.conf:1095) port 80 namevhost cory.example.com (/etc/httpd/conf/httpd.conf:1128) IPV4Address:80 is a NameVirtualHost default server www.example.com (/etc/httpd/conf/httpd.conf:1035) port 80 namevhost dfw.example.com (/etc/httpd/conf/httpd.conf:1065) port 80 namevhost www.example.com (/etc/httpd/conf/httpd.conf:1035) port 80 namevhost chris.example.com (/etc/httpd/conf/httpd.conf:1095) IPV4Address:443 is a NameVirtualHost default server www.example.com (/etc/httpd/conf/httpd.conf:1047) port 443 namevhost www.example.com (/etc/httpd/conf/httpd.conf:1047) port 443 namevhost chris.example.com (/etc/httpd/conf/httpd.conf:1077) wildcard NameVirtualHosts and _default_ servers: _default_:443 www.example.com (/etc/httpd/conf.d/ssl.conf:74) Syntax OK