Apache Reverse Proxy for the WebUI

Hello,

Just sharing a little config pretty useful if you want the webui to share the same port as a web site already hosted with Apache:

RewriteRule ^/gui$ /gui/ [R]
ProxyPass /gui/ http://localhost:8080/
<Location /gui/>
  ProxyPassReverse http://localhost:8080/
  Order Allow,Deny
  Allow from All
</Location>

Add this to a *.conf file in conf.d directory of apache and it will redirect all requests on your standard apache port at location gui/ to a syncthing WebUI hosted at localhost:8080.

This is also useful if you want to reuse your apache configuration such as SSL certificates or authentication.

1 Like

Another possibility to get the same is a .htaccess file in a folder of your webroot (for example gui to get the same like in your example)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*) http://localhost:8080/$1 [P]

this also redirects to https to prevent opening the gui unencrypted over the web. I use this method because I can’t change the config of apache on my shared hosting provider :smiley:

Maybe those methods should be added to the docs that people can easily find that?

2 Likes

It would be awesome if you guys could add these to the documentation repo.

1 Like

I can do it.

3 Likes

Pull request here: https://github.com/syncthing/docs/pull/13

1 Like

Merged into http://docs.syncthing.net/users/reverseproxy.html; thanks.

I use configuration from https://docs.syncthing.net/users/reverseproxy.html#folder-configuration on my nginx server. But when I run myadresse . com/syncthing/ my website reload this url : myadresse . com can you help me?

Could you post your configuration for the relevant virtual host? I expect there’s another location block taking precedence.

it’s here:

    server {
    listen 80;
    listen 443 ssl;
    server_name myurl.fr;
    ssl_certificate /etc/letsencrypt/...../...pem;
    ssl_certificate_key /etc/letsencrypt/...../....pem;

    access_log /var/log/nginx/myurl.log;
    error_log /var/log/nginx/myurl.log;

    location / {
	    proxy_pass ...:2369;
	    proxy_connect_timeout                           90;
	    proxy_send_timeout                              90;
	    proxy_read_timeout                              60;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    proxy_set_header Host $http_host;
	    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /.well-known {
        allow all;
    }

    location /transmission {
        proxy_pass ...:9090;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;

        # include Host header
        proxy_set_header Host $http_host;
    }

  location /sickrage {
    proxy_pass ....:8081;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  }

   location /couch {
    proxy_pass  ....:5050;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  }

   location /headphone {
    proxy_pass  ......:8181;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  }

location /syncthing/ {
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/;
}

location /emby {
    proxy_pass  ....:8096;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
}

}
1 Like