【发布时间】:2019-05-23 02:04:52
【问题描述】:
我在 Rails 5.2.3 应用程序中同时使用 _path 和 _url 助手。一切都在开发中。当我在生产中部署它时,使用 _url 助手设置的 URL 在 HTML 中打印为 https://127.0.0.1 而不是实际主机。
我尝试将此添加到config/environments/production.rb:
config.action_controller.default_url_options = { host: 'example.com' }
但这会将 URL 转换为 https://example.com:3000,从而破坏链接。 (Puma 在 3000 端口上运行,但它在 nginx 后面,它在 80 端口上提供服务。)
有谁知道是什么原因造成的? RAILS_ENV 设置为 production。
【问题讨论】:
-
可能是个愚蠢的问题,但您不是通过
example.com:3000访问您的网站,是吗? -
实时站点位于真实域中。我只是以
example.com为例。该站点本身位于https://example.com/之类的URL。*_url助手生成的链接指向https://example.com:3000/some/path/here。那些不加载,因为nginx在puma前面,访问者只访问80端口。 -
你能在某种示例应用上重现这个吗?
-
这是我所拥有的,它可以工作 config.action_mailer.default_url_options = { host: 'example.com', port: 3000 }
标签: ruby-on-rails