Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx implementation #2

Closed
i300220 opened this issue Nov 2, 2017 · 6 comments
Closed

nginx implementation #2

i300220 opened this issue Nov 2, 2017 · 6 comments

Comments

@i300220
Copy link

i300220 commented Nov 2, 2017

Hello,

Would like to make some websites I maintain compliant,

However, the $loggable variable is already in use and mapped to $uri for specific paths are exempted from logging.

nginx.conf: access_log /var/log/nginx/access.log combined if=$loggable;
snippets/unwanted_uri.conf: map $uri $loggable { ... }

Any suggestion? I know it could be a challenge because the unusual way nginx processes directives.

Thanks.

@void-elf
Copy link
Collaborator

void-elf commented Nov 2, 2017

Hi @i300220!

You don't have to use the variable names chosen in the guides. You could just replace every instance of $loggable with $dnt_loggable or whatever you like, that way there won't be two variables with the same name.

@i300220
Copy link
Author

i300220 commented Nov 2, 2017

Hi,

Although I perfectly understand I could use another variable such as
snippets/unwanted_uri.conf: map $uri $loggable { ... }
map $http_dnt $dnt_loggable { ... }
as you suggested,

What I can't figure out is what to do with the access_log directive.
The 'if' test condition is already defined:
nginx.conf: access_log /var/log/nginx/access.log combined if=$loggable;

nginx is pretty limited in its configuration and doesn't accept booleans in conditions e.g. 'if = $loggable && $dnt_loggable'

@void-elf
Copy link
Collaborator

void-elf commented Nov 4, 2017

Hi @i300220. I'm sorry for misunderstanding your original question, and thank you for the clarification. I think I have an idea for a solution to your problem, but I need some time to test it out first. I'll get back to you in a few days.

@void-elf
Copy link
Collaborator

Hi @i300220, apologies for the incredibly delayed response.

Assuming this is all happening in a server block (otherwise you might not be able to use if), here's a potential solution:

## You have a bunch of code up here that initially sets the value of $loggable
## .......

if ($http_dnt) {
  set $loggable "";
} // if the DNT header is set to anything other than 0, it'll turn off logging

access_log /var/log/nginx/access.log combined if=$loggable;

Note: when I tested this, I had to use set $loggable "" instead of set $loggable 0 to get this to work. The nginx docs say that both should work, but that wasn't the case for me.

Please let me know if you need any more help or if that doesn't work for you.

@i300220
Copy link
Author

i300220 commented Dec 29, 2017 via email

@void-elf
Copy link
Collaborator

Alright, I'll go ahead and close this issue then. Feel free to open another if needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants