静的ファイルの提供

Discourse サーバーのルートに静的ファイルを配信したいですか?

以下の手順で行います。app.yml ファイルの最下部にあるカスタムコマンドセクションで、以下のように記述してください。

## 覚えておいてください、これは YAML 構文です。同じ名前のブロックは一つしか持てません
run:
  - exec: echo "カスタムコマンドの開始"
  - file:
     path: /var/www/discourse/public/myfile.txt
     chmod: "+r"
     contents: |
       ファイルに含まれる内容がここに書かれます。
  - exec: echo "カスタムコマンドの終了"

その後、. /launcher rebuild app を実行してください。

これで、ファイルは http://yourserver.com/myfile.txt からアクセス可能になります。

「いいね!」 12

What is an actual example of where one would want to do this?

「いいね!」 2

Personally i find this really useful. Not to mention that this kind of static file, gives you way more opportunities to use your imagination, files, maybe other website service that you can run as static – etc :smiley:

「いいね!」 2

I’m wondering what “stuff” limitations there are.

contents: |
       Stuff that's in the file goes here.

I imagine simple text strings work well enough, though I also imagine for this to be more useful, markup, links, images, etc. would be desired. I suspect that the more closely “stuff” approaches being a web page the more difficult it would be to not break.

@pfaffman what is your use case and what degree of complexity have you been able to do successfully?

「いいね!」 1

This can also help verifying ownership of the site, e.g. with Google Webmaster Tools :slight_smile:

「いいね!」 5

Site ownership verification can be done with a meta tag in the head as well.

「いいね!」 6

Well, you’ve seen the actual examples that I know about. There are ways not to need it, but I’ve wanted to do this a few times and finally bothered to figure it out. :slight_smile:

「いいね!」 3

非常に興味深く、実用的ですね。これを調整して、複数のファイルをフォルダに投入してアクセスできるようにすることは可能でしょうか?例えば、/var/www/discourse/public/img のようなディレクトリを作成し、yourserver.tld/img/step_1.png のようなファイルを簡単に提供できるようにし、さらに scp やその他の方法でサーバーにアップロードされた任意の数の後続ファイルも扱えるようにしたい場合です。

「いいね!」 1

なぜファイルを提供するためにアプリケーションサーバーを使用するのでしょうか?それらを別の場所に保存して提供した方が安上がりではないでしょうか?

私の特定のユースケースではそうではありません。管理目的に特に役立つ特定のファイルに対してこれを行いたいと考えています。

「いいね!」 1

Cloudflare Worker をこの目的で使用しています。

「いいね!」 2

有料ホスティングについてはどうですか?これを達成する方法はありますか?

プロジェクトのためにSemrushでドメイン所有権を確認する必要があります。他のSemrushユーザーに私のサイトを監査されたくありません。

元の方法がうまくいかなかったら、後でこの方法を試してみます :slight_smile:

医者の言うことを優先します :smiley:

「いいね!」 1