Home 在 Nginx 的容器中开启 debug 模式
Post
Cancel

在 Nginx 的容器中开启 debug 模式

在使用 Nginx 的容器时候,需要开启 debug 日志来进行错误排查。

步骤 1: 使用 nginx-debug 来启动容器

1
$ docker run --name my-nginx -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx nginx-debug -g 'daemon off;'

或者当使用 docker compose 时:

1
2
3
4
5
web:
  image: nginx
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
  command: [nginx-debug, '-g', 'daemon off;']

步骤 2: 在配置文件中启用 debug 日志

1
2
3
server {
  error_log logs/error.log debug;
}

参考资料

This post is licensed under CC BY 4.0 by the author.