Nginx, Deluge, change port to default and use subdomain instead

I have this example.com domain.
I install Wordpress using Nginx, and it's all ok in example.com.
I install Deluge, Deluge WebUI, default port is 8112, and example.com:8112 is all ok again also for Deluge Web UI.
I didn't install anything for Python in Nginx for Deluge, Deluge has it's own web server (I think).
However I want to be able to use Deluge WebUI from subdomain.example.com, instead of (example.com:8112 or subdomain.example.com:8112).
I don't care much if the other solution will keep working as well, I would prefear not to, but what is really important for me is to deliver a working Deluge Web UI at subdomain.example.com
By default, even with Nginx stopped, both subdomain.example.com:8112 and example.com:8112 work and redirect me to Deluge WebUI properly.
However I'm unable to proxy Nginx with default ports (80/443) to Deluge listening in 8112.
I tried many solutions with Nginx, I even managed to redirect to the Deluge Web page, but all I see is a blank page (though inspecting it with dev tool I see that there is the deluge code behind it, and the url inside, like /somewhere/something.css are working as well). It is not even a problem of permission, because (after making a backup copy to restore them properly) I even tried to give 777 with -R in the deluge web directory. The blank page as before actually has some javascript errors, it's likely that that is blocking, but they work on the port 8112, so maybe is some javascript not redirecting to the correct port?
That's one of the Nginx configuration I tried. I tried many, I can't list all the possibilities I tried.
server { listen 80; server_name subdomain.example.com; ## redirect http to https ## rewrite ^ https://$server_name$request_uri? permanent; } server { listen 443; server_name subdomain.example.com; root /usr/share/pyshared/deluge/ui/web; index index.html; location / { proxy_pass httTHIS IS INSIDE A CODE WTH ps://localhost:8112; proxy_redirect off; 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_pass_header Set-Cookie; proxy_pass_header P3P; } location = /favicon.ico { log_not_found off; access_log off; } location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } access_log /var/log/nginx/nginx.example.com.access.log; error_log /var/log/nginx/nginx.example.com.error.log; }
bold is where I edited server specific informations


Solution 1:

Seems i have been able to make it works, following these steps :

Install packages : deluge deluge-webui deluged

Then start deluge-web :

# deluge-web or # deluge-web --fork to have it running in background

Then setup NGinx like this :

server {
   listen       80;
   server_name subdomain.example.com;

  location / {
     proxy_pass http://192.168.0.47:8112; # IP Address of your Server 
  }
}

For https (port 443), first i've setup deluge to use https :

  • I've create a self-signed certificate following instructions here (step One to Four)
  • Then, following this, i've copied server.crt and server.key in $HOME/.config/deluge/ssl
  • Open $HOME/.config/web.conf and setup like this :

    "pkey": "ssl/server.key",
    "cert": "ssl/server.crt",
    "https": true,
    
  • Then restart deluge-web

  • Finally setup NGinx :

    server {
       listen       443;
       server_name subdomain.example.com;
       ssl on;
       ssl_certificate /etc/nginx/ssl/server.crt;
       ssl_certificate_key /etc/nginx/ssl/server.key;
    
       location / {
         proxy_pass https://192.168.0.47:8112; # IP Address of your Server
       }
    }
    

Note that it seems you cannot use deluge with both http and https : you have to choose one or another.