I'm having a docker image with nginx.
I would like to log incoming requests.
My docker-compose file:
nginx:
container_name: my-nginx
image: nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./access.log:/var/log/nginx/test.com.access.log
My nginx config:
server {
listen 80;
listen 443 default_server ssl;
access_log /var/log/nginx/test.com.access.log;
location / {
proxy_pass http://myapp:8080;
proxy_buffering off;
}
}
When I try to replace access_log
directive with following config:
log_format testlog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$request_body"';
access_log /var/log/nginx/test.com.access.log testlog;
I'm getting:
nginx-reverse-proxy | 2018/04/06 11:50:00 [emerg] 1#1: "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10
nginx-reverse-proxy | nginx: [emerg] "log_format" directive is not allowed here in /etc/nginx/conf.d/default.conf:10