# Rancher behind nginx Reverse Proxy

**URL:** https://forums.suse.com/t/rancher-behind-nginx-reverse-proxy/9940
**Category:** General
**Created:** [March 30, 2018, 4:18pm UTC](https://forums.suse.com/t/rancher-behind-nginx-reverse-proxy/9940 "2018-03-30T16:18:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sheq](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sheq/32/3857_2.png) [@sheq](https://forums.suse.com/u/sheq)
#### Post date: [March 30, 2018, 4:18pm UTC](https://forums.suse.com/t/rancher-behind-nginx-reverse-proxy/9940/1 "2018-03-30T16:18:13Z")

</div>

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](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](http://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;
> }
> 
> ```
> }
> `

---

<div class="post-metadata">

### Author: ![sheq](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sheq/32/3857_2.png) [@sheq](https://forums.suse.com/u/sheq)
#### Post date: [April 1, 2018, 9:42am UTC](https://forums.suse.com/t/rancher-behind-nginx-reverse-proxy/9940/2 "2018-04-01T09:42:44Z")

</div>

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.

> <https://github.com/rancher/rancher/issues/7474#issuecomment-377775951>
>
> Using managed network, trying to create port mapping like 127.0.0.1:24004:24004 …opens port on 0.0.0.0 
> 
> Using host network - port fails to open on both 127.0.0.1 and any other ip.
> 
> Use case: I want to create a proxy for logs from docker containers. But because log driver from docker runs on daemon it knows nothing about managed network. I want to create a proxy, running on localhost, that other containers can write to. This proxy will aggregate logs and ship them to other facilities accessible via internal network/internal dns/etc.
> 
> 
> \---
> | Useful | Info |
> | :-- | :-- |
> |Versions|Rancher \`v1.2.2\` Cattle: \`v0.174.13\` UI: \`v1.2.40\` |
> |Access|\`localauth\` \`admin\`|
> |Orchestration|\`Cattle\`|
> |Route|\`stack.index\`|

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.
