配置apache2虚拟主机显示默认页面

配置apache2虚拟主机显示默认页面

我有一个 Apache2 设置,配置如下。我使用占位符域“ilikecabbag.es”代替真实域。

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

但是,当我尝试访问以下其他 VirtualHost 时……

    <Directory /var/www/ilikecabbag.es>
    AllowOverride None
    Require all denied
</Directory>
<VirtualHost *:80>
    DocumentRoot /var/www/ilikecabbag.es/web
    ServerName ilikecabbag.es
    ServerAlias *.ilikecabbag.es
    ServerAdmin [email protected]
    ErrorLog /var/log/ispconfig/httpd/ilikecabbag.es/error.log
    <Directory /var/www/ilikecabbag.es/web>
        # Clear PHP settings of this website
        <FilesMatch ".+\.ph(p[345]?|t|tml)$">
            SetHandler None
        </FilesMatch>
        Options +SymlinksIfOwnerMatch
        AllowOverride All
        Require all granted
        <Files ~ '.php[s3-6]{0,1}$'>
            Require all denied
        </Files>
    </Directory>
    <Directory /var/www/clients/client1/web1/web>
        # Clear PHP settings of this website
        <FilesMatch ".+\.ph(p[345]?|t|tml)$">
            SetHandler None
        </FilesMatch>
        Options +SymlinksIfOwnerMatch
        AllowOverride All
        Require all granted
        <Files ~ '.php[s3-6]{0,1}$'>
            Require all denied
        </Files>
    </Directory>
    # suexec enabled
    <IfModule mod_suexec.c>
        SuexecUserGroup web1 client1
    </IfModule>
    # add support for apache mpm_itk
    <IfModule mpm_itk_module>
        AssignUserId web1 client1
    </IfModule>
    <IfModule mod_dav_fs.c>
        # Do not execute PHP files in webdav directory
        <Directory /var/www/clients/client1/web1/webdav>
            <ifModule mod_security2.c>
                SecRuleRemoveById 960015
                SecRuleRemoveById 960032
            </ifModule>
            <FilesMatch "\.ph(p3?|tml)$">
                SetHandler None
            </FilesMatch>
        </Directory>
        DavLockDB /var/www/clients/client1/web1/tmp/DavLock
        # DO NOT REMOVE THE COMMENTS!
        # WEBDAV BEGIN
        # WEBDAV END
    </IfModule>
</VirtualHost>

我知道 DNS 已正确设置并正常工作。ServerName、serveralias 均已设置...

但它显示的只是默认的 Ubuntu Apache2“它有效”风格的页面。

我做错了什么?使用 ISPConfig 很重要。Ubuntu 22.10

答案1

通常有一个默认配置将捕获端口 80 上的所有流量。您应该检查一些事项:

查看文件夹/etc/apache2/sites-enabled。是否有指向的符号链接000-default.conf?则表示此站点已启用。例如:

lrwxrwxrwx 1 root root 35 apr 16 11:58 000-default.conf -> ../sites-available/000-default.conf

要禁用此站点,请转到命令 shell 并输入 sudo a2dissite 000-default.conf

也许您只需要使用 启用配置sudo a2ensite yourconfig-filename.conf

如果您想进行更多调查,您应该以 root 身份登录(例如sudo -i)并运行一些命令:(我的系统名称是“Jupiter”,我已经使用 以 root 身份登录sudo -i)。一些信息已被删除以隐藏我的网站。

root@Jupiter:~# cd /etc/apache2/
root@Jupiter:/etc/apache2# . ./envvars 
root@Jupiter:/etc/apache2# apache2 -S
AH00558: apache2: Could not reliably determine the servers fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
root@Jupiter:/etc/apache2# 

这将引导您进入 Apache2 的配置文件夹。然后该命令. ./envvars将设置环境以在当前 shell 中运行 Apache2 命令。

该命令apache2 -S将检查您的 Apache2 配置并显示一些可能有用的结果。

!注意!更改 Apache2 的配置(启用/禁用站点或配置文件的内容)后,请务必重新加载或重新启动 Apache2:

  sudo systemctl reload apache2

或者在 Debian 上

  sudo service apache2 reload

希望这可以帮助。

相关内容