通过其域访问我的网络服务器时,提供服务器根目录而不是子文件夹

通过其域访问我的网络服务器时,提供服务器根目录而不是子文件夹

我有一个 apache 2.4.38 网络服务器,运行在我的 Debian 10 Buster 服务器上。在我的 /var/www/html 中,我有一个 index.html 文件和一个文件夹“nextcloud”,其中安装了 nextcloud 实例。如果我在浏览器中输入我的服务器的 IP,则 index.html 文件会显示(这是我想要的行为)。但是,如果我在浏览器中输入我的域名,则只有域名,而没有在 URL 中添加 /nextcloud,nextcloud 会加载。这是不想要的行为。当仅输入我的域名而不指定子文件夹时,我希望显示我的自定义 index.html。在 /etc/apache2/sites-enabled 中,我有 3 个文件:

000-默认.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

nextcloud.conf

<VirtualHost *:80>
     ServerAdmin MY_EMAIL_CENSORED
     DocumentRoot /var/www/html/nextcloud/
     ServerName MY_DOMAIN_CENSORED

     Alias /nextcloud "/var/www/html/nextcloud/"

     <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
     </Directory>

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

RewriteEngine on
RewriteCond %{SERVER_NAME} =MY_DOMAIN_CENSORED
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

nextcloud-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
     ServerAdmin MY_EMAIL_CENSORED
     DocumentRoot /var/www/html/nextcloud/
     ServerName MY_DOMAIN_CENSORED

     Alias /nextcloud "/var/www/html/nextcloud/"

     <Directory /var/www/html/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
     </Directory>

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


SSLCertificateFile /etc/letsencrypt/live/MY_DOMAIN_CENSORED/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/MY_DOMAIN_CENSORED/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

非常感谢您付出的时间、关注和帮助!

西蒙

答案1

您的域名出现在端口 80 和 443 上,这是理所当然的。因此,在MY_DOMAIN_CENSORED加载时,它被称为/var/www/html/nextcloud/。它在 80 和 443 上的样子如下:

DocumentRoot /var/www/html/nextcloud/
ServerName MY_DOMAIN_CENSORED

在 80 和 443 VirtualHost 文件中都更改/var/www/html/nextcloud/为。/var/www/html/

相关内容