Apache 多个虚拟主机文档 Root 不起作用

Apache 多个虚拟主机文档 Root 不起作用

你好我尝试做测试

ubuntu 20.04.01 APACHE : 192.168.23.136
win10  20H2            : DHCP

glpi : /var/www/glpi/index.html
test.com : /var/www/test.com/public_html/index.html
   
file : 000-default.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Win10 browser Web
192.168.23.136/glpi : it work
192.168.23.136/example.com : it doesn't work
192.168.23.136/example.com/public_html : it work

你能告诉我为什么我在 example.com 上看不到我的网页吗

答案1

由此来源,我发现很难理解它如何与同一 IP 和端口的 2 个 DocumentRoot 一起工作。以下方法可能有效:

  <VirtualHost *:80>
    
    ServerName mydomain.no-ip.org
    
    #Default site, accessible by http :// mydomain.no-ip.org/
    <Location />
        DocumentRoot "/var/www/alias"   
        DirectoryIndex index.php
    </Location> 
    
    Alias /mail /usr/share/squrrelmail 
    #Squirrelmail, accessible by http :// mydomain.no-ip.org /mail  
    <Directory /usr/share/squrrelmail>   
        Options FollowSymLinks
        <IfModule mod_php5.c>
                php_flag register_globals off
        </IfModule>
        <IfModule mod_dir.c>
             DirectoryIndex index.php
        </IfModule>
        <Files configtest.php>
                order deny,allow
                deny from all
                allow from 127.0.0.1
        </Files>
    </Directory>
    </VirtualHost>

相关内容