在 Rails 5 中更改我的默认本地主机端口 [英] Change my default localhost port in Rails 5

查看:55
本文介绍了在 Rails 5 中更改我的默认本地主机端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 中更改我的默认本地主机端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆