497 HTTP Request Sent to HTTPS Port
Plain HTTP traffic arriving on the HTTPS port triggers the 497 HTTP Request Sent to HTTPS Port status code in nginx.
Usage
The 497 HTTP Request Sent to HTTPS Port status code indicates the HTTP request is valid, but the server refuses to process because the request was sent in plain text to the HTTPS port. Resolving this error requires either sending the request as HTTPS to the same port, or sending the plain HTTP request to the correct HTTP port.
Note
497 is an nginx-internal status code. nginx
logs the error as 497 internally but returns
400 to the client with the body "The plain
HTTP request was sent to HTTPS port" unless
error_page 497 is configured to map the code
to a different response.
SEO impact
Search engines like Google do not index a URL with 497 HTTP Request Sent to HTTPS Port response status. URLs previously indexed with this code are removed from search results.
Example
A client sends a plain HTTP request to port 443, which expects HTTPS traffic. The nginx server records the failure as 497 HTTP Request Sent to HTTPS Port and, in the default configuration, answers the client with a 400 response carrying the built-in error page.
Request
GET /login HTTP/1.1
Host: www.example.re
Response
HTTP/1.1 400 Bad Request
Server: nginx
Content-Type: text/html
Connection: close
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>
How to fix
The most direct fix uses the nginx
error_page 497 directive to automatically
redirect plain HTTP requests arriving
on the
HTTPS port to the correct protocol:
server {
listen 443 ssl;
server_name www.example.re;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
error_page 497 =301
https://$host:$server_port$request_uri;
}
This catches the 497 internally and sends a 301 redirect to the client, preserving the original port number and request URI.
For standard port 443, a separate server block
listening on port 80 handles the common case of
users typing http:// in the browser:
server {
listen 80;
server_name www.example.re;
return 301 https://$host$request_uri;
}
Update hard-coded http:// URLs in the
application codebase. Configuration files,
environment variables, database records, and
API endpoint definitions referencing http://
cause clients to connect on the wrong protocol
repeatedly.
Ensure the application generates HTTPS URLs for all links, form actions, and redirects. Relative URLs avoid protocol mismatches entirely.
Check upstream proxy or load balancer settings. A reverse proxy terminating TLS and forwarding plain HTTP to nginx on port 443 triggers this error if nginx expects TLS on the same port. Configure the upstream to forward using the same protocol nginx expects.
See also
- 400
- Google: HTTP status codes and network errors
- 301
- nginx ssl_module Error Processing
- HTTP status codes