Can't send data to Sentry through reverse proxy (CORS Error; 111 Connection refused)

Hi!
I have installed the latest Sentry On-Premise 21.4 and run it with docker.

I need to run it via HTTPS, so I (tried to) use nginx as a reverse proxy.

After a lot of research and playing around, I currently have the following nginx configuration:

location / {
	proxy_pass        http://localhost:9000;
	proxy_set_header	Host	$http_host;
	proxy_set_header	X-Forwarded-For	$remote_addr;
	proxy_set_header	X-Forwarded-Proto	$scheme;
	proxy_redirect	off;
}

I have set the system.url-prefix: ‘https://sentry.example.com in config.yml

I enabled all SSL/TLS Options in sentry.conf.py:
SECURE_PROXY_SSL_HEADER = (‘HTTP_X_FORWARDED_PROTO’, ‘https’)
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

Connection to the interface via Browser works, but I just don’t manage to send data to Sentry.

When trying to do so via Javascript, I always get CORS issues like
Access to fetch at ‘https://sentry.example.com/api/1/store/?sentry_key=…&sentry_version=7’ from origin ‘http://domain.local’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

When sending data via PHP (With the Framework Laravel) (Just a test request), i debugged it down to an exception in src/Transport/HttpTransport.php (thrown in the call of $response = $this->httpClient->sendAsyncRequest($request)->wait();):
502 Bad Gateway

I did some more research and found the following entries when checking with sudo docker container logs --follow sentry_onpremise_nginx_1:

2021/04/26 16:52:25 [error] 9#9: *2097 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "POST /api/1/store/ HTTP/1.0", upstream: "http://172.18.0.20:3000/api/1/store/", host: "sentry.example.com"
172.18.0.1 - - [26/Apr/2021:16:52:25 +0000] "POST /api/1/store/ HTTP/1.0" 502 150 "-" "sentry.php.laravel/2.4.2" "80.110.126.197"
2021/04/26 16:52:26 [error] 9#9: *2099 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "POST /api/1/store/ HTTP/1.0", upstream: "http://172.18.0.20:3000/api/1/store/", host: "sentry.example.com"
172.18.0.1 - - [26/Apr/2021:16:52:26 +0000] "POST /api/1/store/ HTTP/1.0" 502 150 "-" "sentry.php.laravel/2.4.2" "80.110.126.197"
2021/04/26 16:52:27 [error] 9#9: *2101 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "POST /api/1/store/ HTTP/1.0", upstream: "http://172.18.0.20:3000/api/1/store/", host: "sentry.example.com"

(of course, my domain is not example.com)

Does anyone have any ideas, what I have misconfigured?

Thanks and best regards

Ok, I just managed to solve my problem:

Instead of
proxy_set_header X-Forwarded-Proto $scheme;

I had to use
proxy_set_header X-Forwarded-Proto https;

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.