開発環境: ポートが欠落しているため、画像が破損しています

I configured a logo in the site settings, but the logo’s URL is missing the default port, i.e. the logo URL looks like this http://localhost/uploads/… rather than http://localhost:3000/uploads/….

I’m starting the development server like this:

RAILS_ENV=development bundle exec rails server

I found that Discourse.base_url is set to "http://localhost" and in config/database.yml, I find this note for the development.hostnames key:

### Don't include the port number here.
Change the "port" site setting instead, at /admin/site_settings.

However, such a site setting does not exist. What do I do?

It’s a hidden setting. Try changing it in the rails console.

bin/rails c

SiteSetting.port = 3000

This works, thank you.

Shouldn’t this be set to 3000 by default in development mode?

No, I don’t think so. Not everyone is using port 3000 for development.

It’s the default, though, isn’t it? That one has to set the hidden port setting is not at all obvious, hence seeing a logo in the development environment not load is unexpected. In other words, setting a custom logo should just work.

Logos work. It’s not something you usually care about in development.

Alternatively, I believe you can use these entries in sitesettings.yml

developer:
  force_hostname:
    hidden: false
    default: '<my-ip>'
  port:
    hidden: false
    default: '<my-port>'

@pfaffman gave me that tip! (and what a life saver that was)

昨日、開発サイトをセットアップする際、元の投稿者とは逆の問題に直面しました。Nginx プロキシの背後で開発サーバーを実行しているため、クリーンな URL を使用したいのですが、設定を変更しても Discourse がサイトロゴを含む多くの内部リンクに :3000 を追加し続けていました。最終的に、lib/discourse.rb の 291〜293 行目が原因であることを突き止めました。

if Rails.env.development? && SiteSetting.port.blank?
    url << ":#{ENV["UNICORN_PORT"] || 3000}"
end

これらの行をコメントアウトしたところ、ロゴや他のリンクが正しく機能するようになりましたが、将来的に他の部分で問題を引き起こす可能性があるかどうかはわかりません。このように SiteSetting.port を上書きするのは、少し直感に反しているように思えます。

少し試行錯誤したところ、SiteSetting.port を 443 に設定し、「HTTPS を強制する」チェックボックスにチェックを入れると、すべて正しく動作するようです(ポート 80 で HTTPS を使わない設定でも同様に動作すると思われます)。以前どこかでポート設定は空のままにしておくべきだと読んだことがありましたが、それは誤ったアドバイスだったようです。