# Serve Static File

**URL:** https://meta.discourse.org/t/serve-static-file/80585
**Category:** Sysadmins
**Tags:** how-to
**Created:** [February 15, 2018, 1:03am UTC](https://meta.discourse.org/t/serve-static-file/80585 "2018-02-15T01:03:40Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 15, 2018, 1:03am UTC](https://meta.discourse.org/t/serve-static-file/80585/1 "2018-02-15T01:03:40Z")

</div>

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:

```plaintext
## 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](http://yourserver.com/myfile.txt)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 15, 2018, 1:53am UTC](https://meta.discourse.org/t/serve-static-file/80585/2 "2018-02-15T01:53:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dbm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbm/32/86954_2.png) [@dbm](https://meta.discourse.org/u/dbm)
#### Post date: [February 15, 2018, 2:01am UTC](https://meta.discourse.org/t/serve-static-file/80585/3 "2018-02-15T02:01:07Z")

</div>

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 😃

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [February 15, 2018, 2:16am UTC](https://meta.discourse.org/t/serve-static-file/80585/4 "2018-02-15T02:16:53Z")

</div>

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

```plaintext
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?

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [February 15, 2018, 9:12am UTC](https://meta.discourse.org/t/serve-static-file/80585/7 "2018-02-15T09:12:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [February 15, 2018, 1:42pm UTC](https://meta.discourse.org/t/serve-static-file/80585/8 "2018-02-15T13:42:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 15, 2018, 4:37pm UTC](https://meta.discourse.org/t/serve-static-file/80585/9 "2018-02-15T16:37:47Z")

</div>

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. 🙂

---

<div class="post-metadata">

### Author: ![mreach](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mreach](https://meta.discourse.org/u/mreach)
#### Post date: [October 28, 2019, 1:38am UTC](https://meta.discourse.org/t/serve-static-file/80585/10 "2019-10-28T01:38:59Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [October 28, 2019, 1:40am UTC](https://meta.discourse.org/t/serve-static-file/80585/11 "2019-10-28T01:40:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mreach](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@mreach](https://meta.discourse.org/u/mreach)
#### Post date: [October 28, 2019, 1:41am UTC](https://meta.discourse.org/t/serve-static-file/80585/12 "2019-10-28T01:41:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fang/32/268176_2.png) [@fang](https://meta.discourse.org/u/fang)
#### Post date: [July 29, 2022, 10:39am UTC](https://meta.discourse.org/t/serve-static-file/80585/13 "2022-07-29T10:39:46Z")

</div>

I‘m using Cloudflare worker for this purpose:

> [@Add files to root directory](https://meta.discourse.org/t/add-files-to-root-directory/86300):
>
> How to upload files to my sites root directory ([https://example.com/file.txt](https://example.com/file.txt)), I’m trying to have [loader.io](http://loader.io) config in the Root directory, i used ./launcher enter app and kept my file in public directory however after updating my instance it is gone.

---

<div class="post-metadata">

### Author: ![priyambodo.w](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/priyambodo.w/32/244149_2.png) [@priyambodo.w](https://meta.discourse.org/u/priyambodo.w)
#### Post date: [October 3, 2022, 2:18pm UTC](https://meta.discourse.org/t/serve-static-file/80585/14 "2022-10-03T14:18:39Z")

</div>

What about paid hosting? Any way to achieve this?

---

<div class="post-metadata">

### Author: ![Rukou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rukou/32/276188_2.png) [@Rukou](https://meta.discourse.org/u/Rukou)
#### Post date: [October 4, 2022, 7:09pm UTC](https://meta.discourse.org/t/serve-static-file/80585/15 "2022-10-04T19:09:21Z")

</div>

I need to verify domain ownership with semrush for my project. I do not want others who use semrush to audit my site.

---

<div class="post-metadata">

### Author: ![spectre](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spectre/32/274073_2.png) [@spectre](https://meta.discourse.org/u/spectre)
#### Post date: [October 4, 2022, 9:47pm UTC](https://meta.discourse.org/t/serve-static-file/80585/16 "2022-10-04T21:47:19Z")

</div>

> [@fang](#):
>
> Cloudflare worker for this purpose

will try this method later on if original method didn’t work 🙂

I prefer what the doctor says 😃
