httptomcatnginxhttpshttp-status-code-505

Getting 505 HTTP Version Not Supported on HTTPS but not on HTTP


I am trying to call a GET api with a parameter which has space in it:

https://abc.xyz/search/web/buildings/search/v2/city/new%20york

The endpoint hits load balancer (nginx) which redirects the request to a suitable machine.

In the response, I get 505 HTTP Version Not Supported error. But when I make the same request to the load balancer using HTTP (using internal IP), it returns the response successfully.

Here are the relevant access logs of both cases:

access log of nginx when called via http

"GET /search/web/buildings/search/v2/city/r%20c HTTP/1.1" S=200 487 T=0.005 R=- 10.140.15.199

access log of the machine when called via http

"GET /search/search/web/buildings/search/v2/city/r%20c HTTP/1.0" 200 36

The above request works fine. but when we request through https, the request in machine comes differently (it should have been d%20a instead of d a)

access log of nginx when called via https

"GET /search/web/buildings/search/v2/city/d%20a HTTP/1.1" S=505 168 T=0.001 R=- 35.200.191.89

access log of the machine when called via https

"GET /search/search/web/buildings/search/v2/city/d a HTTP/1.0" 505 -

Here is the relevant nginx configuration:

upstream searchtomcat {
    least_conn;
        server search-1:8080;
        server search-2:8080;

}

server {

    #listen 443 ssl http2;
    listen 443; 
    client_max_body_size 100M;

...

    location ~* ^/search/(.*)$ {
        proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass  http://searchtomcat/search/search/$1;
            proxy_read_timeout 900;
    }

}

There is nothing in error.log.

What could be the possible reason because of which the machine is getting request in a different manner?


Solution

  • The whole issue.is happening because of the space that is coming in your URL that is being sent over to tomcat. Because of it, a is being interpreted as the HTTP version code and not HTTP/1.0. Solving the extra space issue will solve the problem.

    Using rewrite in location{} block should solve the problem.

    location /search/ {
        rewrite ^/search(/.*) /search/search$1 break;
    
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass  http://searchtomcat;
        proxy_read_timeout 900;
    }
    

    Also, you have different configurations for http and https servers, have a look at the http one. That one seems to be correct.