Nginx Error: "client sent invalid method while reading client request line"

November 26, 2019 311 views
Ruby on Rails Nginx

Hi,

I am running into an error with my Nginx config after following a tutorial on deploying Rails w/Nginx, Puma, and Capistrano.

New versions of the app deploy successfully to the server, however, when I request the droplet’s IP address, I get the following error (according to the Ngninx error log):

2019/11/26 02:49:35 [info] 11483#11483: *9 client sent invalid method while reading client request line, client: xx.xxx.xxx.xxx, server: _, request: "??"

How do I go about debugging this error?

Below is my Nginx config:

upstream puma {
  server unix:///home/deploy/apps/modernpricing/shared/tmp/sockets/modernpricing-puma.sock;
}

server {
  listen 80 default_server;
  listen 443 default_server;
  server_name _;
  ignore_invalid_headers on;

  root /home/deploy/apps/modernpricing/current/public;
  access_log /home/deploy/apps/modernpricing/current/log/nginx.access.log;
  error_log /home/deploy/apps/modernpricing/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri puma;
  location puma {
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

And here’s the /etc/nginx/nginx.conf file

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

2 Answers

Hi @jmarbch,

I have a few suggestions to help you resolve the issue. First one is quite the long shot however you didn’t specify a server_name in your server block.

Additionally, if you try with a blank index.html file is the same error returned? I’m asking as I’ve seen this issue before and it was actually being caused by the application rather than a problem on the server level.

Regards,
KDSys

Hey @KDSys, thanks for offering your help here. I appreciate it.

It looks like my issue was rails-specific as I was able to get past this error by changing force_ssl = true to force_ssl = true in my config/environments/production.rb file.

Of course, the other option is to enable SSL for nginx and the app. That’s up next :)

  • Hi @jmarbach,

    I see, thank you for specifying!

    As for enabling SSL for Nginx and the Application itself, then yes, I would strongly suggest in doing so.

    Regards,
    KDSys

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!