GitLab SSH operations failing behind Nginx reverse proxy

I have set up a webserver (Nginx) as a reverse proxy for multiple servers, with one of them hosting GitLab CE on a VM. The reverse proxy is configured to redirect requests to the GitLab server using a subdomain, and everything seems to be working fine for HTTP requests.

However, when I attempt to perform GitLab operations using SSH (e.g., cloning, pulling, pushing), the operations fail. It appears that SSH is connecting to the Nginx server instead of the GitLab server since the domain initially points to the Nginx server.

Here’s my Nginx configuration for the GitLab subdomain:

server {

    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;

    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/; 
    ssl_certificate_key /etc/letsencrypt/live/; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 

server {
    if ($host = {
        return 301 https://$host$request_uri;
    listen 80;
    return 404; 

How can I configure Nginx and GitLab to ensure that GitLab operations using SSH keys are directed to the GitLab server behind the Nginx reverse proxy?

Any insights or guidance on adjusting the Nginx and GitLab configurations would be greatly appreciated. Thank you!

You could try something like

upstream gitlab-ssh {
  server; #Gitlab SSH IP & Port

server {
  listen 22; # SSH port on your NginxHost that should be forwarded to gitlab
  proxy_pass gitlab-ssh;

You will probably have to use a different SSH port though for gitlab.