Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX: "client sent invalid method while reading client request line"

After setting up SSL for Nginx and making a request, I receive a garbled response with the cryptic message client sent invalid method while reading client request line.

I generated the certificate using Let's Encrypt in an Alpine Docker container (for context, not relevant to the error).

Here is a screenshot:

client sent invalid method while reading client request line

Simplified Nginx virtual host configuration follows:

server {

    listen 443;

    ssl_certificate /vsdroot/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /vsdroot/letsencrypt/live/yourdomain.com/privkey.pem;

    ssl_dhparam /vsdroot/letsencrypt/ssl-dhparams.pem;
    include /vsdroot/letsencrypt/options-ssl-nginx.conf;

    root /vsdroot;

    location / {
        index index.html;
    }

Security Note: My SSL key is located inside the Nginx docroot for local testing only, do not do this on production, or anywhere for that matter!

like image 218
amateur barista Avatar asked Apr 26 '26 05:04

amateur barista


1 Answers

I narrowed down the directive causing the issue and was able to consistently replicate the issue by modifying the listen line on the server block.

Reproduction. Produce gibberish along with client sent invalid method while reading client request line error.

Bad listen line:

server {
    listen 443;

Slightly different error, but still no dice:

server {
    listen ssl;

Product:

Error screenshot

...

FIXED. Error goes away and I'm able to serve my request (plain html, fastcgi_pass, etc).

Configuration:

server {
    listen 443 ssl;

...

💵🪙💲 Profit Screenshot 💲🪙💵 :

Took more than I'd like to admit to narrow the cryptic error down to the single listen directive 🤮🤕.

like image 123
amateur barista Avatar answered Apr 29 '26 01:04

amateur barista