在一台几乎全新的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>
/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/
.
我还 a2ensite test.conf
和 a2dissite 000-default.conf
和 service apache2 reload
所以我认为唯一可能出现错误的地方是 ServerName
和 ServerAlias
. 为什么它们不能工作?
请你用a2ensite启用VirtualHost,并以隐身模式访问网站。