Gitlab SSL with reverse proxy


I fail to configure Gitlab with SSL, because I use a reverse proxy which is not on the same server. The SSL files are located at the reverse proxy server.
When I go to my domain, I get an 502 Bad Gateway nginx error.
Here is my configuration of nginx:

server {
       listen 80;
       listen [::]:80;
        return 301 https://$host$request_uri;
server {
        listen 443 ssl;
        listen [::]:443 ssl;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/;
        ssl_certificate_key /etc/letsencrypt/live/;
        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_buffering off;

And my EXTERNAL_URL in Gitlab is “”.

*When I change the EXTERNAL_URL to HTTP, then everything works fine. HTTP is redirected to HTTPS. But when I create a new project, the project URL is still HTTP.

Do I have to make any further settings?