Apache2 启用捕获所有虚拟主机

Apache2 启用捕获所有虚拟主机

我在 Apache2 服务器上启用了虚拟主机,并且每个域都有其 /etc/httpd/sites-available/domainX.conf 和 /etc/httpd/sites-enabled/domainX.conf 符号链接文件,如下所示:

<VirtualHost *:80>
    ServerName www.domainX.com
    ServerAlias domainX.com
    DocumentRoot /var/www/domainX/html
    ErrorLog /var/www/domainX.com/log/domainX.com-error.log
    CustomLog /var/www/domainX.com/log/domainX-access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.domainX [OR]
RewriteCond %{SERVER_NAME} =domainX
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    ServerName www.domainX
    ServerAlias domainX
    DocumentRoot /var/www/domainX/html
    ErrorLog /var/www/domainX/log/domainX-ssl-error.log
    CustomLog /var/www/domainX/log/domainX-ssl-access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domainX/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domainX/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/domainX/chain.pem
</VirtualHost>

现在,当访问我的 IP 时,它将显示我的一个域的内容,并且我了解到它使用它找到的第一个配置 - 这是有意义的,因为列出的域是以“a”开头的域。

现在我学会了Apache2 禁用捕获所有虚拟主机我应该使用_default_如下所示的主机:http://httpd.apache.org/docs/2.0/vhosts/examples.html#default

现在我创建了一个/var/www/默认/index.html文件以及/etc/httpd/sites-available/default.conf配置内容如下:

<VirtualHost _default_:*>
DocumentRoot /var/www/default
</VirtualHost>

同时创建其 /etc/httpd/sites-enabled/default.conf 符号链接。

现在,当我尝试测试我的配置时,httpd -t出现以下错误:

httpd: Syntax error on line 355 of /etc/httpd/conf/httpd.conf: Could not open configuration file /etc/httpd/sites-enabled/default.conf: Too many levels of symbolic links

我还尝试删除之前创建的 default.conf 文件并尝试仅添加:

<VirtualHost _default_:*>
DocumentRoot /var/www/default
</VirtualHost>

在访问 Web 服务器的 IP(以“a”开头的 IP)时显示的域的配置文件的开头。

所有这些都需要正确重启 httpd,这样设置才会生效。我很确定我漏掉了什么,做错了,但不确定是什么。

答案1

Too many levels of symbolic links强烈建议你有一个符号链接循环,例如

/etc/httpd/sites-available/default.conf -> ../sites-enabled/default.conf

/etc/httpd/sites-enabled/default.conf -> ../sites-available/default.conf

的输出ls -l /etc/httpd/sites-*/default.conf将显示这一点。

相关内容