Apache2 ServerName和ServerAlias不能正常工作。

问题描述 投票:0回答:1

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

我已经建立了一个 test.conf 归入 /etc/apache2/sites-available/

含有以下内容。

<VirtualHost *:80>
    ServerAdmin [email protected]
    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>

本地主机正在工作localhost is working

/etc/hosts config可能正在工作,如 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/.

enter image description here

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

所以我认为唯一可能出现错误的地方是 ServerNameServerAlias. 为什么它们不能工作?

apache browser server virtualhost server-name
1个回答
0
投票

请你用a2ensite启用VirtualHost,并以隐身模式访问网站。

© www.soinside.com 2019 - 2024. All rights reserved.