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

debops.nginx there is no way to create a custom log_format #83

Closed
le9i0nx opened this issue Dec 11, 2017 · 4 comments
Closed

debops.nginx there is no way to create a custom log_format #83

le9i0nx opened this issue Dec 11, 2017 · 4 comments

Comments

@le9i0nx
Copy link
Contributor

le9i0nx commented Dec 11, 2017

The current configuration does not allow changing the format of the log.
Because format must be specified before the line indicating the path to the log.

log_format main '$remote_addr - $remote_user [$time_local] '
                '"$request_method $scheme://$host$request_uri $server_protocol" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;

I think I can create a variable with the right conditions.
in this file

# Logging
access_log {{ nginx_http_access_log | default(nginx_log_path + '/access.log') }};
error_log {{ nginx_http_error_log | default(nginx_log_path + '/error.log') }};

@drybjed drybjed added this to To do in Webserver infrastructure via automation Dec 11, 2017
@drybjed
Copy link
Member

drybjed commented Dec 11, 2017

Sure, sounds like good idea. Although, perhaps the log formats could be managed globally in nginx.conf, and then referenced in the server configuration? That way role could manage a few different, default log formats for different outputs. And you can add another variable for custom log formats defined by the user.

@le9i0nx
Copy link
Contributor Author

le9i0nx commented Dec 15, 2017

I think that here it is not quite rightly written. If you look at the official documentation.
When I checked it must be always a string of log_format and it should be higher access_log.

https://nginx.ru/en/docs/http/ngx_http_log_module.html

{% block nginx_tpl_block_log %}
{% if item.name|d() %}
{% set nginx_tpl_access_log_format = '' %}
{% if item.access_log_format is defined %}
{% set nginx_tpl_access_log_format = ' ' + item.access_log_format %}
{% elif nginx_access_log_format is defined %}
{% set nginx_tpl_access_log_format = ' ' + nginx_access_log_format %}
{% endif %}
access_log {{ (item.log_path | d(nginx_log_path)) + '/' + item.access_log | d(item.filename | d(item.name if item.name is string else item.name[0]) + '_access') }}.log{{ nginx_tpl_access_log_format }};
error_log {{ (item.log_path | d(nginx_log_path)) + '/' + item.error_log | d(item.filename | d(item.name if item.name is string else item.name[0]) + '_error') }}.log;
{% endif %}
{% endblock %}

@drybjed
Copy link
Member

drybjed commented Dec 15, 2017

The log_format directive is allowed only in the http { } section of the nginx configuration, not in server { } block. So, these entries will need to be defined outside of the server configuration. They could be defined in a separate file in /etc/nginx/conf.d/ directory, maybe that would be a better choice than putting everything in /etc/nginx/nginx.conf.

@le9i0nx
Copy link
Contributor Author

le9i0nx commented Dec 15, 2017

if log_format is created in the folder conf.d, then this line should be higher access_log

include {{ nginx_etc_path }}/conf.d/*.conf;

access_log {{ nginx_http_access_log | default(nginx_log_path + '/access.log') }};

@le9i0nx le9i0nx closed this as completed Dec 20, 2017
Webserver infrastructure automation moved this from To do to Done Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants