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