提供静态文件

想在 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 个赞