【发布时间】:2021-02-14 07:03:00
【问题描述】:
好吧,我有一个 Bizzard 问题,这是第一次,
操作系统:Centos 7
Apache:
Server version: Apache / 2.4.6 (CentOS)
Server built: Aug 5 2020 16:41:29
我的问题如下: 我在httpd.cnf配置文件中没有重定向,在hosts文件中也没有,.htaccess不能重定向到https。
所有http请求都返回错误:
<! DOCTYPE HTML PUBLIC "- // IETF // DTD HTML 2.0 // EN">
<html> <head>
<title> 400 Bad Request </title>
</head> <body>
<h1> Bad Request </h1>
<p> Your browser sent a request that this server could not understand. <br />
Reason: You're speaking plain HTTP to an SSL-enabled server port. <br />
Instead use the HTTPS scheme to access this URL, please. <br />
</p>
</body> </html>
我在 conf.d 文件夹中创建了 unsafe.cnf 文件,将这一行放入:HTTPProtocolOptions unsafe。
在我的主机中,我测试了两种解决方案:
1 - 重定向到 https:
<VirtualHost example.com:80>
SuexecUserGroup "#1008" "#1008"
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost example.com:443>
SuexecUserGroup "#1008" "#1008"
ServerName example.com
DocumentRoot /directory/html
SSLEngine On
...
</VirtualHost>
2- 其他解决方案:
<VirtualHost example.com:80>
SuexecUserGroup "#1008" "#1008"
ServerName example.com
ServerAlias www.example.com
DocumentRoot /directory/html
...
</VirtualHost>
<VirtualHost example.com:443>
SuexecUserGroup "#1008" "#1008"
ServerName example.com
ServerAlias www.example.com
DocumentRoot /directory/html
SSLEngine On
...
</VirtualHost>
3- 解决方案:
在 .htaccess 中:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
所以无论有没有这样的配置,服务器都可以正常工作,https 和 http 返回错误的请求。
使用卷曲:
# curl -sD - http://jelocalise.maroccrm.com
HTTP/1.1 400 Bad Request
Date: Fri, 30 Oct 2020 13:32:40 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_fcgid/2.3.9 PHP/5.6.40
Content-Length: 362
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead use the HTTPS scheme to access this URL, please.<br />
</p>
</body></html>
N.B : 对不起我的英语不好
【问题讨论】:
-
分享有问题的错误日志。
标签: apache .htaccess ssl httpd.conf