nginx - 如何正确调试 Sentry 并查找 502 nginx 错误的原因

标签 nginx nginx-reverse-proxy nginx-config sentry

我是 Sentry 和 Nginx 的新手,我很难弄清楚我的实例中发生了什么,以及为什么我从 Nginx 收到 502。

哪里可以找到问题的根源?我尝试使用 tail -100/var/log/nginx/error.log 但我不知道问题出在哪里......

来自tail/var/log/nginx/error.log的输出:

2021/04/30 17:08:55 [error] 68825#68825: *7 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.28.132.95, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "https://myip:9000/", host: "mydomain.com"
2021/04/30 17:09:08 [alert] 68825#68825: *17 open socket #9 left in connection 3
2021/04/30 17:09:08 [alert] 68825#68825: *16 open socket #8 left in connection 4
2021/04/30 17:09:08 [alert] 68825#68825: *15 open socket #13 left in connection 5
2021/04/30 17:09:08 [alert] 68825#68825: aborting

我发现的唯一奇怪的事情是上游使用我的实例IP地址,并且主机被解析为mydomain.com

我的 Nginx /etc/nginx/sites-available/default:

    server {
      server_name mydomain.com;
      location / {
        proxy_pass         http://localhost:9000;
        proxy_redirect     off;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
      }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
    server {
    if ($host = mydom) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
      listen 80;
      server_name mydomain.com;
    return 404; # managed by Certbot
}

docker-compose.yml(nginx):

      nginx:
    <<: *restart_policy
    ports:
      - '127.0.0.1:$SENTRY_BIND:80/tcp'
    image: "nginx:1.16"
    volumes:
      - type: bind
        read_only: true
        source: ./nginx
        target: /etc/nginx
    depends_on:
      - web
      - relay

system.internal-url-前缀:

system.internal-url-prefix: 'https://mydomain:9000'

sentry.conf.py:

##############
# Web Server #
##############

SENTRY_WEB_HOST = "0.0.0.0"
SENTRY_WEB_PORT = 9000
SENTRY_WEB_OPTIONS = {
    "http": "%s:%s" % (SENTRY_WEB_HOST, SENTRY_WEB_PORT),
    "protocol": "uwsgi",
    # This is needed in order to prevent https://git.io/fj7Lw
    "uwsgi-socket": None,
    "so-keepalive": True,
    # Keep this between 15s-75s as that's what Relay supports
    "http-keepalive": 15,
    "http-chunked-input": True,
    # the number of web workers
    "workers": 3,
    "threads": 4,
    "memory-report": False,
    # Some stuff so uwsgi will cycle workers sensibly
    "max-requests": 100000,
    "max-requests-delta": 500,
    "max-worker-lifetime": 86400,
    # Duplicate options from sentry default just so we don't get
    # bit by sentry changing a default value that we depend on.
    "thunder-lock": True,
    "log-x-forwarded-for": False,
    "buffer-size": 32768,
    "limit-post": 209715200,
    "disable-logging": True,
    "reload-on-rss": 600,
    "ignore-sigpipe": True,
    "ignore-write-errors": True,
    "disable-write-exception": True,
}

###########
# SSL/TLS #
###########

# If you're using a reverse SSL proxy, you should enable the X-Forwarded-Proto
# header and enable the settings below

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

有什么想法我可能会错过吗?

提前致谢并致以亲切的问候

最佳答案

您可以尝试docker-compose日志网络中继

您可能会对这个主题感兴趣: forum sentry

关于nginx - 如何正确调试 Sentry 并查找 502 nginx 错误的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67344835/

相关文章:

nginx - grpc_send_timeout 不起作用,Nginx 意外关闭 GRPC 流

linux - nginx 中的 proxy_pass 不支持 #

nginx - 配置nginx发出后台请求

wordpress - Nginx反向代理https内容

nginx - 你应该在docker里面安装nginx吗?

docker - 无法访问包含 Vue JS 前端应用程序的 Docker 容器

bash - nginx在docker上的配置问题-对没有实例的docker进行故障排除

使用反向 NGINX 代理在 Docker 中部署 WordPress 站点

nginx - 如何通过 nginx 通过 HTTPS 连接到安全的 WebSocket SurrealDB 实例?

docker - 如何为多个环境创建单个 NGINX.conf 文件