Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to listen host Loopback #2160

Closed
xxz199539 opened this issue Feb 27, 2024 · 2 comments
Closed

how to listen host Loopback #2160

xxz199539 opened this issue Feb 27, 2024 · 2 comments

Comments

@xxz199539
Copy link

xxz199539 commented Feb 27, 2024

Hi, i want to listen ::1 and localhost in my rack server. my code:

def self.run_service(ser_proc_name, ser_cls_name, service_file, port)
	pid = fork do
		dir, file = File.dirname(service_file), File.basename(service_file)
		Dir.chdir(dir)
		load file
		$0 = ser_proc_name
            ssl_options = {
                :private_key_file => nil,
                :cert_chain_file => nil,
                :verify_peer => false,
            }
	    rack_handler_config = {
		:server => 'thin',
		:Host => '::1', 
		:Port => port
	    }
	    ser_cls_name = ser_cls_name.downcase.include?("web") ? ser_cls_name : ser_cls_name + "Service"
	    Rack::Handler::Thin.run(DDI.const_get(ser_cls_name), rack_handler_config) do |server|
                  server.ssl = true
                  server.ssl_options = ssl_options
	    end
	end
	Process.detach(pid)
end

but it not work for localhost, i got error when execute commad 'telnet localhost 20121'. so how can i config the 'Host' to listen 'localhost' and '::1' at the same time?
thanks.

@xxz199539
Copy link
Author

xxz199539 commented Feb 27, 2024

when i set

rack_handler_config = {
		:server => 'thin',
		:Host => '::', 
		:Port => port
	    }

i can get response by 'telnet :: 20121' and 'telnet 0.0.0.0 2012'.so has the same way to support '::1' and 'localhost'(Loopback address)?

@xxz199539 xxz199539 changed the title how to listen host include localhost and ::1? how to listen host Loopback Feb 28, 2024
@ioquatix
Copy link
Member

Thank you for bringing this up. After reviewing the situation, it's clear that this isn't a bug or issue with Rack itself. The behavior you're experiencing is related to how hosts are configured in your environment.

Your proposed solution to use :: as the host to listen on all interfaces, including localhost and ::1, is correct. This configuration should resolve the issue you were facing.

Closing this issue as it is not a bug with Rack. If you have any further questions or run into additional problems, feel free to reach out. GitHub Discussions are a better forum for these kinds of problems: https://github.com/rack/rackup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants