Serve Static File

Want to serve a static file at the root of your Discourse server?

Here’s what to do. In the bottom of your app.yml file, down in the custom commands section, do something like this:

## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"
  - file:
     path: /var/www/discourse/public/myfile.txt
     chmod: "+r"
     contents: |
       Stuff that's in the file goes here.
  - exec: echo "End of custom commands"

And . /launcher rebuild app
The file will then be accessible as 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 лайк