Apache 虚拟主机重定向到 https

Apache 虚拟主机重定向到 https

我已设置 VirtualHost 以重定向到 https。当我在域中输入 ServerName 时,它​​会将我带到 https 站点。但是,无论我输入什么域,它都会将我带到 https 站点。这是为什么?以下是我的配置。

<VirtualHost *:80>
    ServerName storage.example.com
    Redirect permanent / https://storage.example.com/
</VirtualHost>

<VirtualHost *:443>
    Alias /files /var/www/files 
    ServerName storage.example.com
    DocumentRoot /var/www/nextcloud/

    <Directory /var/www/nextcloud/>
        Options +FollowSymlinks
        AllowOverride All

        <IfModule mod_dav.c>
            Dav off
        </IfModule>

        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
    </Directory> 

    # SSL
    SSLEngine on
    SSLCertificateFile  /etc/letsencrypt/live/storage.example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/storage.example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/storage.example.com/fullchain.pem

    Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;"     

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

</VirtualHost>

答案1

这是因为您没有为其指定任何子句。请尝试使用类似下面的内容来代替永久重定向:

RewriteCond %{HTTP_HOST} ^storage.example.com
RewriteRule ^(.*)$ https://storage.example.com$1 [R,L]

相关内容