Apache / Letsencrypt - 重定向到https不在子域上工作

时间:2017-01-19 16:52:14

标签: apache .htaccess ssl vhosts lets-encrypt

我有一个Ubuntu 16.04 VPS。我使用Letsencrypt作为我的ssl证书,在创建或创建证书时,他们会询问您是否希望轻松或安全地访问。安全意味着无论如何都会重定向到https。

这适用于主页,但它不适用于子域。我没有重定向到https,我只看到我的index.html只是apache默认页面。

那么我该如何解决这个问题呢?

My Virtualhost:

<VirtualHost *:80>
    ServerName school.luukwuijster.eu
    Redirect / https://school.luukwuijster.eu

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html/school.luukwuijster.eu/public/

    <Directory /var/www/html/school.luukwuijster.eu/public/>
        AllowOverride All
        Require all granted
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =school.luukwuijster.eu
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

</VirtualHost>

LE-SSL:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName school.luukwuijster.eu

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html/school.luukwuijster.eu/public/

    <Directory /var/www/html/school.luukwuijster.eu/public/>
        AllowOverride All
        Require all granted
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =school.luukwuijster.eu
# Some rewrite rules in this file were were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/luukwuijster.eu-0003/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/luukwuijster.eu-0003/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

出于某种原因,它只是没有重定向。

当我转到http://luukwuijster.eu时,我被重定向到https://luukwuijster.eu

这样工作正常,但当我转到http://school.luukwuijster.eu时,我没有被重定向并且看到与https://luukwuijster.eu

上相同的页面

当我去https://school.luukwuijster.eu时,我没有被重定向,但我确实看到了正确的页面。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试将第3行从Redirect / https://school.luukwuijster.eu更改为RedirectPermanent / https://school.luukwuijster.eu/

BTW目前您的SSL证书仅对api.luukwuijster.eu有效。您应该将school.luukwuijster.eu和您要保护的所有其他域添加到letsencrypt配置中。