Rancher behind nginx Reverse Proxy

Hello,

i have a small problem with running my rancher apps. So here is the basic setup:

I’am running rancher behind an nginx proxy running on Ubuntu Server. This is working perfectly fine.
If i call “http:// rancher.example.com” this will be redirected to https:// as expected, when i try to access the rancher ui directly by adding the port to the url like rancher.example.com:8080
i’am redirected to the https url again.

When i call an deployed app i will be redirected when using the url without the port. But redirection will not work when i add the port to the url so that it is possible to access it without https.
I tried to map the url with the server port in nginx config but that didn’t help.
I also blocked the complete port with ufw but that dosen’t help neither.
So is it a nginx missconfiguration or where could the problem be?

The following nginx-config files are included by the nginx.conf:
Whitespaces are only in there because i can’t post more than two links.

default config:

Summary server { location /.well-known/acme-challenge { root /var/www/letsencrypt; }
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed$
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # manag$
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {

if ($host = www. rancher. example. com) {

    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = rancher. example. com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = app. example. com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = app. example .com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;

    server_name example .com www. example .com rancher .example .com www. rancher .example .com" app .example.com www. app.example. com;
return 404; # managed by Certbot

}

Here is a config for an app-url (rancher is the same pattern):

Summary map $http_upgrade $connection_upgrade { default Upgrade; '' close; }

server {
listen 443 ssl http2;
server_name app. example .com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http: //127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    # This allows the ability for the execute shell window to remain open f$
    proxy_read_timeout 900s;
}

}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name “www.app .example. com;”

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    #include /usr/local/etc/nginx/nginx-ssl.conf;

    location / {
            return 301 https://app .example .com$request_uri;
    }

}

I found this topic on github, i think when i would be able to expose the ports to localhost only it would solve the problem.

Edit: Found a workaround for Rancher 1.6.15 you can expose ports to 127.0.0.1 when you set a specific host under the scheduling tab. So i guess this will be useless for multihost setups.