SSL 文件夹重定向问题 - ubuntu 16.04/Apache 2.4

SSL 文件夹重定向问题 - ubuntu 16.04/Apache 2.4

我们已经为网站启用了 SSL。如果我们输入“https://example.com/“(使用 htpps://),它指向正确的文件夹。没有https://(example.com)它指向根文件夹 (/var/www/html)。如何将两者都指向正确的文件夹“/var/www/html/example.com/public_html”?

.conf如下

<Directory /var/www/html/example.com/public_html>
    Require all granted
</Directory>

<VirtualHost xx.xx.xx.xx:443>
        SSLEngine On
        SSLCertificateFile /etc/apache2/ssl/example.crt
        SSLCertificateKeyFile /etc/apache2/ssl/example.key
        SSLCACertificateFile /etc/apache2/ssl/example.cer

        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin test@example
        DocumentRoot /var/www/html/example.com/public_html

        ErrorLog /var/www/html/example.com/logs/error.log
        CustomLog /var/www/html/example.com/logs/access.log combined

</VirtualHost>

答案1

将以下内容添加到配置中即可(除非ServerNameServerAlias具有值的指令example.com已经在 VHost 中的某处定义):

<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin test@example
        DocumentRoot /var/www/html/example.com/public_html
        ErrorLog /var/www/html/example.com/logs/error.log
        CustomLog /var/www/html/example.com/logs/access.log combined
</VirtualHost>

相关内容