首页 > 解决方案 > 通过 Nginx 和 Django 记录内部服务器错误

问题描述

我正在尝试记录通过我的 django 应用程序发生的内部服务器错误。

我已经通过 nginx 配置()为访问日志和错误日志设置了位置nginx.conf

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
...

设置后我只是重新加载了 nginx。每个访问都记录在access.log文件中,没有任何问题,但内部服务器错误永远不会记录在error.log文件中,但 nginx 确实可以访问它,因为它包含的唯一内容是[notice] 23802#0: signal process started)。

我的 django 应用程序中有一个特定的 API,它返回 json(用于 Ajax)。不幸的是,该视图发生了一些内部错误(Ajax 仅记录状态代码和错误名称)。


我认为内部服务器错误不应该由 Nginx 处理,这是真的吗?如果是这样,我是否需要通过 Django 手动记录内部服务器错误?(process_exception()?)。如果没有,是不是nginx配置有问题。

谢谢!

标签: djangonginxlogging

解决方案


推荐阅读