在 Rails 5 中更改我的默认本地主机端口

编程入门 行业动态 更新时间:2024-10-26 03:26:37
本文介绍了在 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 中更改我的默认本地主机端口

本文发布于:2023-08-07 03:41:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316768.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   主机   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!