puma / puma

A Ruby/Rack web server built for parallelism

Home Page:https://puma.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Staging environment, request.ENV['HTTP_HOST'] displays 2 urls when it should be a single url

fuggfuggfugg opened this issue · comments

Describe the bug
Recently upgraded my Rails project from 2.1.9 to 7.0. Local environment works fine. I deployed to staging and noticed issue in unauthorized host where the host showed 2 urls (staging.mysite.com, staging.mysite.com) when it should only be a single url.
Deployed to AWS, Single EC2 instance (for now) behind a LoadBalancer.

Puma config:

Please copy-paste your Puma config AND your command line options here.
[77528] * Puma version: 6.4.0 (ruby 3.2.3-p157) ("The Eagle of Durango")
[77528] * Min threads: 10
[77528] * Max threads: 10
[77528] * Environment: production
[77528] * Workers: 1

To Reproduce
I am unsure how to reproduce this but I can provide my findings from debugging:

This is the output of my request object.

"SERVER_SOFTWARE"=>"puma 6.4.0 The Eagle of Durango",
"GATEWAY_INTERFACE"=>"CGI/1.2",
"REQUEST_METHOD"=>"GET",
"SERVER_PROTOCOL"=>"HTTP/1.0",
"HTTP_X_FORWARDED_FOR"=>"52.3.XXX.XXX, 10.12.XX.XX",
"HTTP_X_FORWARDED_PROTO"=>"https",
"HTTP_HOST"=>"staging.mysitehere.com, staging.mysitehere.com",

Comparing this with the old environment, I can see a single url entry

I tried overriding the env[HTTP_HOST] and assign it to a single url

"SERVER_SOFTWARE"=>"2.12.0",
"GATEWAY_INTERFACE"=>"CGI/1.2",
"REQUEST_METHOD"=>"GET",
"REQUEST_PATH"=>"/home",
"HTTP_VERSION"=>"HTTP/1.0",
"HTTP_X_FORWARDED_FOR"=>"52.3.XXX.XXX, 10.12.XX.XX",
"HTTP_X_FORWARDED_PROTO"=>"https",
"HTTP_HOST"=>"staging.mysitehere.com",

I then tried to manually override the HTTP_HOST variable in the handle_request method in the request.rb file. This fixed my issue. However I am currently stuck unable to locate where/how HTTP_POST is being set. Any input is appreciated.

Expected behavior
Expecting env[HTTP_HOST] to be a single entry.

Desktop (please complete the following information):

  • OS: Ubuntu 14
  • Puma Version 6.4.0

SOLVED - Issue was with my nginx config.
SOLUTION - Comment proxy_set_header Host $http_host; if defined in any .conf file. There is also another entry in the proxy_params file. Try commenting it out and see what works.