Skip to content

Instantly share code, notes, and snippets.

@tobstarr
Last active September 25, 2015 19:43
Show Gist options
  • Save tobstarr/5b10c49a47ff36b4ab8d to your computer and use it in GitHub Desktop.
Save tobstarr/5b10c49a47ff36b4ab8d to your computer and use it in GitHub Desktop.

Logfmt with Nginx

Start

$ docker rm -f nginx
$ docker run --name nginx -d -p 8080:8080 -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro nginx:1.9.3

Test

$ curl -H 'User-Agent: User Agent with " Double Quotes' 'http://127.0.0.1:8080/path with space and " quotes'

Logs

$ docker logs
remote_addr=172.17.42.1 forwarded_for="-" host="127.0.0.1:8080" method=GET status=200 length=0 total=0.000 upstream_time=- ua="User Agent with \x22 Double Quotes" uri="/path with space and \x22 quotes" ref="-"
logs:
docker logs -f nginx
start:
docker rm -f nginx
docker run --name nginx -d -p 8080:8080 -v $(shell pwd)/nginx.conf:/etc/nginx/nginx.conf:ro nginx:1.9.3
test:
curl -H 'User-Agent: User Agent with " Double Quotes' 'http://127.0.0.1:8080/path with space and " quotes'
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main 'remote_addr=$remote_addr forwarded_for="$http_x_forwarded_for" host="$http_host" method=$request_method status=$status length=$body_bytes_sent '
'total=$request_time upstream_time=$upstream_response_time '
'ua="$http_user_agent" uri="$request_uri" ref="$http_referer"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 8080;
location / {
return 200;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment