提供静态文件

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

Very interesting and useful. Can this be tweaked to allow many files to be dumped into a folder for access? Say you want to make /var/www/discourse/public/img so that yourserver.tld/img/step_1.png can be served up easily and any number of subsequent files that are scp’d or uploaded in some way to the server?

1 个赞

Why would you use an application server to serve files? Wouldn’t it be cheaper to store and serve them elsewhere?

Not in my particular use case. I would prefer to do this for certain files that are specifically useful for admin purposes.

1 个赞

我正在为此目的使用 Cloudflare Worker:

2 个赞

关于付费托管有什么看法?有什么方法可以实现吗?

我需要使用 semrush 验证我的项目的域名所有权。我不想让其他使用 semrush 的人审核我的网站。

如果原始方法不起作用,我稍后会尝试此方法 :slight_smile:

我更喜欢医生说的话 :smiley:

1 个赞