我有一个示例 python 应用程序作为 docker 容器运行并配置了 apache2.4 和 openssl (python-server.py):
PORT_NUMBER = 80
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/good":
self.wfile.write("HTTP/1.0 404 Not Found\r\n\r\nThis is the good page.".encode("utf-8"))
return
elif self.path == "/bad":
self.wfile.write("HTTP/1.0 b'404 Not Found'\r\n\r\nThis is the bad page.".encode("utf-8"))
return
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
# Send the html message
self.wfile.write(
"Test app to produce good and bad responses\n"
"For successful 404 response, use /good URL\n"
"For incorrectly formatted response, use /bad URL\n".encode("utf-8"))
return
server = HTTPServer(('', PORT_NUMBER), myHandler)
print('Started httpserver on port ', PORT_NUMBER)
结果 以下是我分别看到的 /good 和 /bad 的回复:
curl -ik --cert '<your cert>' https://<app-host-name>/good --resolve <app-host-name>:443:<ip>
HTTP/1.1 404 Not Found
Date: Fri, 14 Apr 2023 08:06:14 GMT
Server: Apache/2.4.53 (Unix) OpenSSL/3.0.7+
Transfer-Encoding: chunked
This is the good page.%
curl -ik --cert '<your cert>' https://<app-host-name>/bad --resolve <app-host-name>:443:<ip>
HTTP/1.1 200 OK
Date: Fri, 14 Apr 2023 08:18:02 GMT
Server: Apache/2.4.53 (Unix) OpenSSL/3.0.7+
Transfer-Encoding: chunked
HTTP/1.0 b'404 Not Found'
This is the bad page.%
如何配置 apache,使其不会为响应主体格式错误的任何端点返回 200ok?
Apache 应该返回 404 或 500 而不是 200ok