skip to Main Content

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

The localhost is working: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/.

enter image description here

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?

2

Answers


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

    Login or Signup to reply.
  2. Ensure that the ssl certificate for the site includes both example.com and http://www.example.com
    and ServerAlias is set to http://www.example.com

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search