将http重定向到https(https将http重定向到默认值) [英] Redirect http to https (https works http redirects to default)

查看:153
本文介绍了将http重定向到https(https将http重定向到默认值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个owncloud设置,我正在尝试将HTTP永久重定向到https.

I have an owncloud setup, and Im trying to make a permanent http redirection to https.

当我键入 https://sub.domain.com 时,我的https conf工作正常. 但是 http://sub.domain.com 重定向到debian apache默认页面.

Well my https conf works just fine when i type https://sub.domain.com. But http://sub.domain.com redirects to debian apache default page.

我还试图实现正确的Strict-Transport-Security HTTP标头配置.

Im also trying to achieve a proper Strict-Transport-Security HTTP header configuration.

我的设置是:

<VirtualHost *:80>
    ServerAdmin info@domain.com
    ServerName sub.domain.com
    ServerAlias www.sub.domain.com
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ErrorLog /var/www/owncloud/error.log
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin info@domain.com
        ServerName sub.domain:443
        DocumentRoot /var/www/owncloud/public_html

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

        SSLEngine on
        SSLCertificateFile /etc/ssl/cloud/sub.domain.com.crt
        SSLCertificateKeyFile /etc/ssl/cloud/sub.domain.com.key
        SSLCertificateChainFile /etc/ssl/cloud/sub.domain.com.ca-bundle

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>
        <IfModule mod_headers.c>
                     Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
        </IfModule>
        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        # MSIE 7 and newer should be able to use keepalive
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    </VirtualHost>
</IfModule>

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

推荐答案

解决方案是使用sub.domain.com:80代替第一行的*:80.

The solution was instead of *:80 on the first line, to use sub.domain.com:80.

这篇关于将http重定向到https(https将http重定向到默认值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆