Connection issues to VM and 502 Bad Gateway behind nginx reverse proxy

I was struggling with an erratic connection to my newly setup syncthing server running on a VM behind an nginx reverse proxy. After a while I figured out that this is related to my SSH connection with the server. All the following work when I am SSHed into the VM, and fail when I am out:

  • Syncing to my local device (shows VM as “Disconnected”, if I hardcode its static IP I get a “connection refused”)
  • Connection to the webinterface via nginx (502 Bad Gateway)
  • Connection to the webinterface via http://IP:8384 (“Firefox can’t establish a connection”)

Evidently this has nothing to do with nginx itself, that is only a symptom, but for completeness I will add that I followed the guide on Reverse Proxy Setup — Syncthing v1 documentation and have the following config file for nginx:

server {
  listen 80;
  listen [::]:80;
  server_name DOMAIN;
#  location / { return 301 https://$host$request_uri; }
#server {
#  listen 443 ssl http2;
#  listen [::]:443 ssl http2;
#  server_name DOMAIN;
#  ssl_certificate /etc/letsencrypt/live/DOMAIN/fullchain.pem;
#  ssl_certificate_key /etc/letsencrypt/live/DOMAIN/privkey.pem;

  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_pass              http://localhost:8384/;

    proxy_read_timeout      600s;
    proxy_send_timeout      600s;

The commented out part makes it use SSL, but the issue is the same either way.

How are you running syncthing?

What you describe sounds like you’re running syncthing as a systemd user service. Those only run when the user is logged in.

You are totally correct!

1 Like

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