# Nginx to server static files?

**URL:** https://meta.discourse.org/t/nginx-to-server-static-files/201323
**Category:** Development
**Created:** [August 22, 2021, 9:21am UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323 "2021-08-22T09:21:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![valsha](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/valsha/32/230631_2.png) [@valsha](https://meta.discourse.org/u/valsha)
#### Post date: [August 22, 2021, 9:21am UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323/1 "2021-08-22T09:21:20Z")

</div>

Hi, Does it make sense to serve static files using nginx?  
Something like:

```plaintext
 location ~ ^/assets/(?<asset_path>.+)$ {
      expires 1M;
      add_header Cache-Control "max-age=2629746, public";
    }
location ~ ^/user_avatar/(?<user_avatar_path>.+)$ {
      expires 1M;
      add_header Cache-Control "max-age=2629746, public";
    }
location ~ ^/uploads/(?<uploads_path>.+)$ {
      expires 1M;
      add_header Cache-Control "max-age=2629746, public";
    }

```

We are use nginx outside the container. Thank you.

---

<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: [August 22, 2021, 1:15pm UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323/2 "2021-08-22T13:15:38Z")

</div>

I guess you didn’t follow [How to install Discourse in production](https://meta.discourse.org/t/how-to-install-discourse-in-production/142537)?

---

<div class="post-metadata">

### Author: ![valsha](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/valsha/32/230631_2.png) [@valsha](https://meta.discourse.org/u/valsha)
#### Post date: [August 22, 2021, 1:34pm UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323/3 "2021-08-22T13:34:26Z")

</div>

@pfaffman  
I am using your guide to almost the fullest extent.  
Except for the part concerning nginx  
my **app.yml**

```plaintext
  # - "templates/web.ssl.template.yml"
  # - "templates/web.letsencrypt.ssl.template.yml"
  # - "80:80" # http
  # - "443:443" # https

```

Can i use your [discourse/config/nginx.sample.conf at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/config/nginx.sample.conf) in production?  
Thanks.

---

<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: [August 23, 2021, 1:35pm UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323/4 "2021-08-23T13:35:45Z")

</div>

I don’t think that there is any reaon to have the external NGINX serve those files directly. I think that you can, but it’ll be hard to configure, hard to maintain, and provide virtually no benefit. If you thought that it would make things faster, why would you use a reverse proxy at all?

---

<div class="post-metadata">

### Author: ![valsha](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/valsha/32/230631_2.png) [@valsha](https://meta.discourse.org/u/valsha)
#### Post date: [August 23, 2021, 2:45pm UTC](https://meta.discourse.org/t/nginx-to-server-static-files/201323/5 "2021-08-23T14:45:53Z")

</div>

@pfaffman  
I am using it this way because there are other sites running on this server, not just discourse.
