Apache2 现在指向新的默认页面

Apache2 现在指向新的默认页面

我的 Apache2 服务器有一个新的默认页面:(Apache2 Ubuntu Default Page位于/var/www/html/index.html)

我的所有网络服务器提供的文件都位于:/opt/lampp/htdocs文件夹。

为什么会发生这种变化以及如何解决它?

答案1

Ubuntu 存储库中的 Apache2 从 获取其默认位置/etc/apache2/sites-available

默认页面配置是000-default.conf该位置的文件。

您可以修改该页面,也可以将其用作模板并创建自己的配置文件。如果您想要一个以/opt/lampp/htdocs为服务器路由的页面,您可以按以下方式进行:

1) 将00-default.conf文件复制到新名称。为了便于记忆,您可以将文件名命名mywebsite.conf为 ,以便进行配置www.mywebsite.conf

现在编辑这个新页面并做以下更改:

更改自:

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

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

改成:

<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.mywebsite.com
        ServerAlias mywebsite.com

        ServerAdmin webmaster@localhost
        DocumentRoot /opt/lampp/htdocs

        # We must also allow access to the new root directory; by
        # default only access to /var/www is allowed.
        <Directory /opt/lampp/htdocs>
            Require all granted
        </Directory>

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

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

为您的网站创建虚拟主机后,使用以下命令启用此新配置:

$ sudo a2ensite mywebsite.conf

然后系统将提示您重新启动服务器以使更改生效,您可以这样做:

$ sudo systemctl restart apache2

两个重要的变化是:

  1. 服务器名称
  2. 文档根目录

现在,您将能够通过 ServerName 或 ServerAlias 指令中给出的名称访问您的网站。

我在配置文件示例中留下了注释,以显示可以通过删除“#”所需选项来启用的选项。此外,注释也是解释配置选项的宝贵资源。

相关内容