Help with Error 400 and Bad Gateway 502 on Nginx Proxy Manger

All has been working fine, until it wasn’t. On investigation I found that my BT Router had wiped all of my Port Forwarding Addresses? No idea what caused this, but even after putting all my addresses back in, still no Remote Access to Home Assistant via a Browser or the HA App. Only Local Access in the house works anymore.

I have tried almost everything that I can find via searches and YouTube. But nothing prevails. I also delved into getting “help” from different A.I.s but that has just made everything worse!

Has anyone got any suggestions that might help me to get back on track, and allow me to access HA from outside of my Home Network.

Same issue.
After some update, it just stopped working. I didn’t discover this right away; I’ve been struggling with it for three days now, without success.
Nginx config:

server {
    server_name  *********;
    access_log      /var/log/nginx/ha.access.log main;
    error_log       /var/log/nginx/ha.error.log;
    location / {
            proxy_pass http://***.***.***.***:8123;
            proxy_set_header Host $http_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;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_read_timeout 86400;
            proxy_send_timeout 86400;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {            root   html;        }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    location ~ /\.ht {             deny  all;         }
    location ^~ /.well-known/acme-challenge {
     alias /var/www/html/dehydrated;
    }

listen 443 ssl; # managed by Certbot
listen [::]:443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/*********/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/*********/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

}

I have a BT Smart Hub 2 that I think must have done an Update, as all my Port Forwards were deleted. I removed and cleared the cache then reinstalled Nginx and I still get 400 or 502 Errors?

I’ve eventually got mine working. Initially I couldn’t access HA from outside my home at all, and that turned out that my router had somehow lost its port-forwarding rules, so I restored ports 80/443.

With the help from AI, I then simplified the reverse-proxy setup so that HTTPS terminates at Nginx Proxy Manager and NPM forwards HTTP internally to HA on port 8123. I also had to make sure HA trusted the NPM reverse-proxy network.

I subsequently discovered a separate certificate issue in that the Let’s Encrypt certificate was valid for my main DuckDNS domain, but it didn’t include my ‘ha.’ subdomain. I had to create a new certificate containing the ‘ha.’ subdomain, and assign it to the HA Proxy Host fixed the Android app’s “hostname certificate mismatch” error.

So, if you’re seeing something similar, I’d check:

Your Router has the port forwarding set for 80/443
NPM → HA scheme/port
HA Trusted Proxies
Most importantly, check whether the SSL certificate actually contains your exact HA “hostname” in it’s Subject Alternative Names. (I had 3 sub domain names!).

My final setup was HTTPS externally → NPM → HTTP internally → HA:8123, and everything is now working again, including the Android app.

Your problem may not be the same as mine, but hopefully this might give you a few ideas on things to check?