简体   繁体   中英

Apache2 ServerName and ServerAlias not working

On a nearly fresh Ubuntu 20.04 LTS computer, I would like to set up a virtual host on my local machine. So I created a index.html under /var/www/test/ with the following content: you have entered a test page

I have set up a test.conf file under /etc/apache2/sites-available/

with the following content:

<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>

The localhost is working: 本地主机正在工作

/etc/hosts config is probably working as indicated by 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

but browser cannot bring me to the domain which should now be hosted in /var/www/test/ .

在此处输入图像描述

I have also a2ensite test.conf and a2dissite 000-default.conf and service apache2 reload

So I think the only possible place for error to occur is ServerName and ServerAlias . Why are they not working?

Could you please enable VirtualHost using a2ensite and access site in incognito mode.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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