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

Configuring nginx to get struct logs #61

Closed
supriyopaul opened this issue Mar 2, 2018 · 1 comment
Closed

Configuring nginx to get struct logs #61

supriyopaul opened this issue Mar 2, 2018 · 1 comment
Assignees

Comments

@supriyopaul
Copy link
Contributor

supriyopaul commented Mar 2, 2018

How to configure nginx to produce only struct log so that logagg can pick them up?

@supriyopaul
Copy link
Contributor Author

Nginx struct log Configuration

  • To get the nginx logs in json format we have to modify the nginx.conf file in /etc/nginx directory.

  • Modify the Logging Settings section in the nginx.conf file by adding the below lines:

	##
	# Logging Settings
	##
	log_format  json  '{'
                    '"remote_addr": "$remote_addr",'
                    '"remote_user": "$remote_user",'
                    '"timestamp": "$msec",'
                    '"request": "$request",'
                    '"status": "$status",'
                    '"request_time": "$request_time",'
                    '"body_bytes_sent": "$body_bytes_sent",'
                    '"http_referer": "$http_referer",'
                    '"http_user_agent": "$http_user_agent",'
                    '"http_x_forwarded_for": "$http_x_forwarded_for",'
                    '"upstream_response_time": "$upstream_response_time"'
                    '}';
	access_log /var/log/nginx/access.log json;
	error_log /var/log/nginx/error.log;

  • Modify the line: access_log /var/log/nginx/access.log; to access_log /var/log/nginx/access.log json;

  • To test nginx config file

nginx -t
  • It shows like:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful
  • Restart the nginx by using command:
/etc/init.d/nginx restart

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

1 participant