apache - HTTPD Centos 7 错误请求
问题描述
好吧,我有一个疯狂的问题,这是第一次,
操作系统: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>
NB : 对不起我的英语不好
解决方案
原因:您对启用 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。
推荐阅读
- python - 在使用 python 2.7 时从 Boto2 迁移到 Boto3
- javascript - 当我们删除 HostListener 时,Angular HTML 绑定不起作用
- python - 如何让我的客户为每个发送的请求从服务器接收超过 1 个响应?
- node.js - 在将 xml 转换为 json 时获得实际响应
- c# - 如何在 Dafny 3.1.0 中生成读取文件的可执行文件?
- reactjs - 组合来自 ReduxToolkit Slice 的操作
- reactjs - 使用反应路由器重定向以注销用户
- python - 如何将图像从内存传递到烧瓶变量
- axios - NuxtJS Axios 代理自签名证书链错误
- javascript - 如何在Javascript中将浮点数作为实际数值相加