Welcome! Log In Create A New Profile


Re-enable access_log after it has been set to off (same block level)

April 21, 2023 05:08AM
Default nginx.conf on Ubuntu 20.04 turns access_log on.

Our provisioning prefers to deal in conf overrides in nginx/conf.d rather than automated file-editing (i.e. not editing the nginx.conf config but overriding it).

By default we want access_log to be off.

Adding an override (http block) setting access_log to go to /dev/null doesn't affect the previous declaration from nginx.conf...apparently it just sends access log to both places (/var/log/nginx/access.log and /dev/null).

Setting access_log "off" in a http block override does indeed disable the default access logging from nginx.conf... but the problem is that we can't turn it back on when needed at the http block level.

It appears that "access_log off;" is special (docs indicate so) and disables all access_log at the current config block level regardless of the order the access_log config directives appear (ie you can't turn it "off" and then back on at the same config block).

Use case: Certain servers use special format nginx access logs to construct metrics for prometheus via mtail and these metrics should be for all of nginx (http block) rather than certain sub-blocks/servers. As these servers tend to have a LOT of traffic, we don't really want extra request logging hanging around taking up disk.

Is there something I am missing? Seems like the only options here are:

- leave the default access log on and trust logrotate to keep it from filling up the disk, add a second access_log in custom format when needed via override.
- script automated editing of nginx.conf to remove the default access_log and then add in our custom access_log via overrides when needed.

Both options require avoiding the use of "access_log off;"

Any other options I missed?

Subject Author Posted

Re-enable access_log after it has been set to off (same block level)

matp April 21, 2023 05:08AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 213
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready