【问题标题】:How to remove port 3000 from URLs in production Rails app如何从生产 Rails 应用程序中的 URL 中删除端口 3000
【发布时间】: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


【解决方案1】:

而不是

 config.action_controller.default_url_options = { host: 'example.com' }

在 production.rb 中试试这个

Rails.application.routes.default_url_options[:host] = 'your_host.com'

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-03-01
    • 2020-02-20
    • 2017-12-06
    • 2016-02-06
    相关资源
    最近更新 更多