Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将HTTP重定向到HTTPS Apache2_Apache_.htaccess - Fatal编程技术网

将HTTP重定向到HTTPS Apache2

将HTTP重定向到HTTPS Apache2,apache,.htaccess,Apache,.htaccess,我正在尝试将http重定向到https。 我找到了很多答案,但没有一个对我有用。 我不知道为什么,可能是apache2配置错误? 我也在.htaccess中尝试,但也没有发生任何事情 仅此错误: 错误的请求 您的浏览器发送了此服务器无法理解的请求。 原因:您正在对启用SSL的服务器端口使用普通HTTP。 请改用HTTPS方案访问此URL 这是我的虚拟主机文件 #Redirect HTTP TO HTTPS RewriteEngine On RewriteCond %{HTTPS} off Re

我正在尝试将http重定向到https。 我找到了很多答案,但没有一个对我有用。 我不知道为什么,可能是apache2配置错误? 我也在.htaccess中尝试,但也没有发生任何事情

仅此错误:

错误的请求 您的浏览器发送了此服务器无法理解的请求。 原因:您正在对启用SSL的服务器端口使用普通HTTP。 请改用HTTPS方案访问此URL

这是我的虚拟主机文件

#Redirect HTTP TO HTTPS

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]

#VHOSTS


<VirtualHost *:443>
    Servername www.latoya.eu
    ServerAlias latoya.eu www.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:443>
    Servername board.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:443 *:80>
    Servername secure.latoya.eu
    Documentroot /var/www/latoya
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLEngine on
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>

<VirtualHost *:80 *:443>
    Servername static.kritzelpixel.com
    Documentroot /var/www/static.kritzelpixel.com
    ErrorLog /path/to/log/error.log
    CustomLog /path/to/log/access.log combined
    SSLCertificateFile /path/to/ssl/files/pem.crt
    SSLCertificateKeyFile /path/to/ssl/files/private.key
    SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle
</VirtualHost>
#将HTTP重定向到HTTPS
重新启动发动机
重写条件%{HTTPS}关闭
重写规则(.*)https://%{SERVER_NAME}/%$1[R,L]
#维奥斯特
服务器名www.latoya.eu
ServerAlias latoya.eu www.latoya.eu
Documentroot/var/www/latoya
ErrorLog/path/to/log/error.log
CustomLog/path/to/log/access.log组合
斯伦金安
SSLCertificateFile/path/to/ssl/files/pem.crt
SSLCertificateKeyFile/path/to/ssl/files/private.key
SSLCertificateChainFile/path/to/ssl/files/pem.ca-bundle
Servername board.latoya.eu
Documentroot/var/www/latoya
ErrorLog/path/to/log/error.log
CustomLog/path/to/log/access.log组合
斯伦金安
SSLCertificateFile/path/to/ssl/files/pem.crt
SSLCertificateKeyFile/path/to/ssl/files/private.key
SSLCertificateChainFile/path/to/ssl/files/pem.ca-bundle
Servername secure.latoya.eu
Documentroot/var/www/latoya
ErrorLog/path/to/log/error.log
CustomLog/path/to/log/access.log组合
斯伦金安
SSLCertificateFile/path/to/ssl/files/pem.crt
SSLCertificateKeyFile/path/to/ssl/files/private.key
SSLCertificateChainFile/path/to/ssl/files/pem.ca-bundle
Servername static.kritzelpixel.com
Documentroot/var/www/static.kritzelpixel.com
ErrorLog/path/to/log/error.log
CustomLog/path/to/log/access.log组合
SSLCertificateFile/path/to/ssl/files/pem.crt
SSLCertificateKeyFile/path/to/ssl/files/private.key
SSLCertificateChainFile/path/to/ssl/files/pem.ca-bundle
在同一VirtualHost标记中使用“VirtualHost*:80*:443”或相反的名称是完全不正确的,因为一个VirtualHost不能同时是SSL,也不能同时是SSL

apachehttpd并没有为此而大喊大叫,这是因为您“可以”在同一虚拟主机中使用不同的端口,但这显然不是为了将SSL端口和非SSL端口结合在一起而设计的

因此,我的建议是,将您的配置更正为看起来正常,即分别使用特定的virtualhost*:80和virtualhost*:443

在VirtualHost*:80条目中,您可以使用您的案例的特定主机名重定向/以从80重定向到443一行,而无需使用mod_rewrite

要重定向到SSL mod_,不需要重写,这太过分了

简而言之:

<VirtualHost *:80>
ServerName example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
#other directives here
</VirtualHost>

ServerName example.com
重定向/https://example.com/
ServerName example.com
斯伦金安
#这里还有其他指示
如果其他名称具有不同的配置,则与之相同。

在同一VirtualHost标记中使用“VirtualHost*:80*:443”或相反的名称是完全不正确的,因为一个VirtualHost不能同时是SSL,也不能同时是SSL

apachehttpd并没有为此而大喊大叫,这是因为您“可以”在同一虚拟主机中使用不同的端口,但这显然不是为了将SSL端口和非SSL端口结合在一起而设计的

因此,我的建议是,将您的配置更正为看起来正常,即分别使用特定的virtualhost*:80和virtualhost*:443

在VirtualHost*:80条目中,您可以使用您的案例的特定主机名重定向/以从80重定向到443一行,而无需使用mod_rewrite

要重定向到SSL mod_,不需要重写,这太过分了

简而言之:

<VirtualHost *:80>
ServerName example.com
Redirect / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
#other directives here
</VirtualHost>

ServerName example.com
重定向/https://example.com/
ServerName example.com
斯伦金安
#这里还有其他指示

如果其他名称具有不同的配置,则与之相同。

您需要在
SSLEngine关闭时设置端口80
,在
SSLEngine打开时设置端口443
谢谢。。。!解决了我的问题,您需要在
SSLEngine关闭时设置端口80
,在
SSLEngine打开时设置端口443
谢谢。。。!解决了我的问题*:80和*:443都可以是SSL或非SSL,但按照约定,端口80应该是非SSL的。允许它的语法并不能防止它成为不应用于一致性抖动的完全异常。最后,一个虚拟主机将是SSL或不是SSL,但不是两者都是。*:80和*:443都可以是SSL或非SSL,但按照约定,端口80应该是非SSL的。允许它的语法不会阻止它成为不应用于一致性抖动的完全异常。最后,一个虚拟主机将是SSL或不是SSL,但不是两者都是。