【问题标题】:HTTPD Centos 7 Bad RequestHTTPD Centos 7 错误请求
【发布时间】: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


【解决方案1】:

原因:您对启用 SSL 的服务器端口使用纯 HTTP。

您不知何故在端口 80 上配置了 HTTPS,该端口通常用于纯 HTTP。这就是以下成功的原因:

$ curl -k  https://jelocalise.maroccrm.com:80
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Dolibarr Development Team">
....

可能在您的配置中的某处(您只显示一部分)为端口 80 或某些 VirtualHost 全局配置了 SSLEngine。

【讨论】:

  • 你说得对,谢谢,我的一个 VirtualHost 有这样的声明: 并且在 SSLEngine 内部,所以我复制了配置并删除了 SSLEngine 内部: 80 岁,现在正在工作,谢谢。
猜你喜欢
  • 2015-11-20
  • 2016-07-03
  • 2015-02-27
  • 2020-08-05
  • 2018-09-09
  • 2018-04-21
  • 2020-10-21
  • 2016-10-29
  • 1970-01-01
相关资源
最近更新 更多