繁体   English   中英

Apache2 ServerName 和 ServerAlias 不起作用

[英]Apache2 ServerName and ServerAlias not working

在几乎全新的 Ubuntu 20.04 LTS 计算机上,我想在我的本地计算机上设置一个虚拟主机。 于是我在/var/www/test/下创建了一个index.html ,内容如下: you have entered a test page

我在/etc/apache2/sites-available/下设置了一个test.conf文件

内容如下:

<VirtualHost *:80>
    ServerAdmin webmaster@zhihu.com
    DocumentRoot /var/www/test/
    ServerName zhihu.com
    ServerAlias www.zhihu.com
    <Directory /var/www/test/>
        Options Indexes FollowSymLinks
        AllowOverride All 
        Require all granted     
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

本地主机正在工作: 本地主机正在工作

/etc/hosts配置可能正在工作,如ping所示

ping zhihu.com
PING zhihu.com (127.0.1.1) 56(84) bytes of data.
64 bytes from xxx (127.0.1.1): icmp_seq=1 ttl=64 time=0.045 ms

但是浏览器无法将我带到现在应该托管在/var/www/test/中的域。

在此处输入图像描述

我还有a2ensite test.confa2dissite 000-default.confservice apache2 reload

所以我认为唯一可能发生错误的地方是ServerNameServerAlias 为什么他们不工作?

您能否使用 a2ensite 启用 VirtualHost 并以隐身模式访问站点。

Ensure that the ssl certificate for the site includes both example.com and www.example.com and ServerAlias is set to www.example.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM