I am using rails 5 which works with a default puma server and listen to localhost:3000
I want it to listen to a new port like 192.168.0.0:3000
Can anyone help ? thank you
Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .
For example, Rails pass a default port of 3000 to the server. So if you boot your app using rails server and you don't specify a PORT environment variable you would expect this to connect to port 4000 but instead it connects to 3000 .
Rails 5 comes with puma, which is configured in config/puma.rb
. You can change the default port number in that file, or override it by setting the PORT
environment variable before starting rails.
@Iceman: in Rails 5, it is not required to monkey patch Rails to override the default port, so the answer you referred to is no longer relevant.
Edit: upon re-reading the original question, I notice that you do not want to change the port, but rather the bind address. You can do that by editing config/puma.rb
and replacing the port
statement with a bind
statement:
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
#port ENV.fetch("PORT") { 3000 }
bind 'tcp://192.168.0.1:3000'
@JohnLinux: Rails is not aware of the fact that Puma uses a different bind address, so it tells you about what it passed down to Puma (which Puma ignores). There are several issues in both Rails' and Puma's github issue trackers that deal with this, and AFAICT there have been changes on both ends to pass control of the bind address back to Rails, but I have not toyed yet with updated gems to see how far that got. It is important to comment out the port
statement, otherwise Puma actually binds to both!
You can bind the server using -b option like
rails s -p 3000 -b 0.0.0.0
where -p is for port option and 0.0.0.0 will bind to you localhost ip if it is 192.168.0.0 and you can open your app with connected devices in your network.
If you are looking to change your local ip address..that's not a rails question.
Change default port in rails 5
change config/puma.rb
port ENV.fetch("PORT") { 3000 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With