我正在使用 Rails 5,它与默认的 puma 服务器一起工作并侦听 localhost:3000
I am using rails 5 which works with a default puma server and listen to localhost:3000
我想让它监听一个新的端口,比如 192.168.0.0:3000
I want it to listen to a new port like 192.168.0.0:3000
有人可以帮忙吗?谢谢
推荐答案Rails 5 自带 puma,在 config/puma.rb 中配置.您可以更改该文件中的默认端口号,或者在启动 rails 之前通过设置 PORT 环境变量来覆盖它.
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:在 Rails 5 中,不需要给 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.
重新阅读原始问题后,我注意到您不想更改端口,而是要更改绑定地址.您可以通过编辑 config/puma.rb 并将 port 语句替换为 bind 语句来实现:
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 不知道 Puma 使用不同的绑定地址这一事实,因此它会告诉您它传递给 Puma 的内容(Puma 忽略了它).Rails 和 Puma 的 github 问题跟踪器中都有几个问题可以解决这个问题,而且 AFAICT 两端都发生了变化,将绑定地址的控制权传回给 Rails,但我还没有玩弄更新的 gems 来看看如何远到了.注释掉 port 语句很重要,否则 Puma 实际上绑定到两者!
@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!
更多推荐
在 Rails 5 中更改我的默认本地主机端口
发布评论