# 如何更改 nginx 日志轮转周期

**URL:** <https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453>\
**Category:** Self-hosting\
**Created:** [2016年四月29日 13:48 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453 "2016-04-29T13:48:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年四月29日 13:48 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/1 "2016-04-29T13:48:57Z")

</div>

How can I change this and have it retained across upgrades ?

If I edit the `web.template.ym`l in `/var/discourse/templates` I get a problem pulling new versions.

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [2016年四月29日 14:43 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/2 "2016-04-29T14:43:32Z")

</div>

You can add the commands to change the rotation period in your container file 🙂

---

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年四月29日 14:54 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/3 "2016-04-29T14:54:33Z")

</div>

In app.yml ?  
Any pointer to where I can see what I need to change or how to do this ?

— EDIT ----  
Ok - I figure that logrotate is being used, I can see /etc/logrotate.d/nginx in the container.

If I edit that file in the container won’t it get destroyed when I rebuild my container and I’ll have to redo the change ?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年五月2日 03:56 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/4 "2016-05-02T03:56:00Z")

</div>

You run your commands AFTER we run our commands, so you can change whatever and have it persisted.

---

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年五月3日 08:28 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/5 "2016-05-03T08:28:17Z")

</div>

Just in case I’ve got the wrong end of the stick, I need to make my change in the container in `/etc/logrotate.d/nginx` ?

If so - when I rebuild the container the configuration change will be lost. It’s not persisted outside the container like configuration I specify in app.yml. I need to write and run a script of my own to maintain my configuration.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年五月3日 09:11 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/6 "2016-05-03T09:11:01Z")

</div>

Nope, you would use an after hook never edit supplies shared templates

---

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年五月3日 09:58 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/7 "2016-05-03T09:58:18Z")

</div>

OK - I can hook into the rebuild process after your commands ?  
How and where do I do that - apologies for not being familiar with all the ins and outs of how discourse is building the containers.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年五月3日 10:18 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/8 "2016-05-03T10:18:10Z")

</div>

Eg:

> <https://github.com/discourse/discourse_docker/blob/master/samples/web_only.yml#L69-L70>

injects after:

> <https://github.com/discourse/discourse_docker/blob/master/templates/web.template.yml#L83>

---

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年五月3日 10:20 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/9 "2016-05-03T10:20:16Z")

</div>

Fantastic - I get it now 🙂

---

<div class="post-metadata">

**Author:** ![gearoid](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gearoid](https://meta.discourse.org/u/gearoid)\
**Post date:** [2016年五月3日 10:46 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/10 "2016-05-03T10:46:02Z")

</div>

Looking at web.template.yml there’s no hooks after logrotate’s configuration

> <https://github.com/discourse/discourse_docker/blob/master/templates/web.template.yml#L202>

Is the `custom commands` section of my app.yml a suitable location to put this until there’s a hook I can use ?

```plaintext
## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"

```

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年五月3日 11:14 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/11 "2016-05-03T11:14:00Z")

</div>

feel free to do a PR to add a hook there if you need.

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2024年六月8日 12:45 UTC](https://meta.discourse.org/t/how-to-change-nginx-log-rotation-period/43453/12 "2024-06-08T12:45:38Z")

</div>

此主题在 2961 天后自动关闭。不再允许回复。
