Nginx Docker 镜像中的 log_format 无效

Nginx Docker 镜像中的 log_format 无效

我在 Nginx 配置中的 http 级配置中设置了以下内容,但似乎被忽略了。也许我遗漏了什么?

我的[原始] nginx.conf:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent UCT=$upstream_connect_time UHT=$upstream_header_time URT=$upstream_response_time RT=$request_time "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';

    # Symlinked to /dev/stdout in the upstream Nginx image
    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    
    include /etc/nginx/conf.d/*.conf;
}

我的[原始] server.conf:

server {
    listen 80;
    listen [::]:80;

    sendfile on;
    client_max_body_size 20M;
    keepalive_timeout 10;

    location /css {
        root /static;
    }

    location /images {
        root /static;
    }

    location /static {
        root /static;
    }

    location / {
        include uwsgi_params;

        uwsgi_read_timeout 120s;
        uwsgi_send_timeout 120s;

# TODO(dustin): Until we can figure this out in the context of ECS.
#        uwsgi_pass unix:/shared/sellback_website.sock;
        uwsgi_pass sellback-website-app:8000;
    }
}

我的Dockerfile:

FROM nginx:latest

ADD config/nginx.conf /etc/nginx/nginx.conf
ADD config/server.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

给定上述配置的访问日志的内容/格式:

10.0.2.57 - - [13/Jun/2022:05:00:05 +0000] "GET /healthcheck HTTP/1.1" 200 3 "-" "ELB-HealthChecker/2.0" "-"
10.0.3.211 - - [13/Jun/2022:05:00:33 +0000] "GET /healthcheck HTTP/1.1" 200 3 "-" "ELB-HealthChecker/2.0" "-"
10.0.1.78 - - [13/Jun/2022:05:00:33 +0000] "GET /healthcheck HTTP/1.1" 200 3 "-" "ELB-HealthChecker/2.0" "-"
10.0.2.57 - - [13/Jun/2022:05:00:34 +0000] "GET /healthcheck HTTP/1.1" 200 3 "-" "ELB-HealthChecker/2.0" "-"

我期待更多时间信息(我刚刚添加)。

作为参考,这显示了公共图像中默认检测到的 Dockerfile,但我认为它在这里没有帮助:

https://github.com/docker-library/repo-info/blob/master/repos/nginx/remote/latest.md

相关内容