# 如何自定义特定附件的 MIME 媒体类型？

**URL:** <https://meta.discourse.org/t/how-to-customize-mime-media-type-emitted-for-certain-attachments/282111>\
**Category:** Self-hosting\
**Created:** [2023 年10 月 13 日 06:03 UTC](https://meta.discourse.org/t/how-to-customize-mime-media-type-emitted-for-certain-attachments/282111 "2023-10-13T06:03:35Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![xyzzy](https://avatars.discourse-cdn.com/v4/letter/x/e36b37/32.png) [@xyzzy](https://meta.discourse.org/u/xyzzy)\
发布日期： [2023 年10 月 13 日 06:03 UTC](https://meta.discourse.org/t/how-to-customize-mime-media-type-emitted-for-certain-attachments/282111/1 "2023-10-13T06:03:36Z")

</div>

我有一些用户希望将带有不常见文件扩展名的文件附加到他们的帖子中。这些文件基本上是文本文件，因此我希望 Discourse 的 NGINX Web 服务器在用户从 Discourse 下载这些文件时发出 MIME 媒体类型“text/plain”。

不出所料，NGINX 无法识别这些不常见的文件扩展名。因此，它目前为这些文件发出“application/octet-stream”。

我已经成功更新了 NGINX 配置，指示它为这些扩展名使用“text/plain”，但当用户从帖子下载文件时，它仍然坚持使用“application/octet-stream”。

这是我所做的（此示例中的文件扩展名是“.foo”和“.bar”）：“

1. sudo vi /var/discourse/containers/app.yml  
在“run”部分，就在“End of custom commands”echo 语句之前，添加了：

```plaintext
  - replace:
      filename: /etc/nginx/mime.types
      from: "txt;"
      to: "txt foo bar;"

```

1. cd /var/discourse
2. sudo ./launcher rebuild app

我已“bash”进入容器并验证 NGINX 文件是否已从

```plaintext
text/plain txt;

```

正确更新为

```plaintext
text/plain txt foo bar;

```

我哪里做错了？

我也尝试使用“replace”机制更新 /etc/nginx/conf.d/discourse.conf 中的“types”部分，但那也没有奏效。

提前感谢！

---

_[View the full topic](https://meta.discourse.org/t/how-to-customize-mime-media-type-emitted-for-certain-attachments/282111)._
