Nginx proxy manager in docker and lxc container help needed

I can’t figure out how to do this or even make it work.
On my host, I have one lxd container running jupyter and it has reverse proxy set like this:
lxc config device add ju_lxd port5000 proxy listen=tcp:127.0.0.1:5000 connect=tcp:127.0.0.1:5000
And then I have docker running on my host and one of the docker containers is running npm( Nginx proxy manager).
Before npm, I had nginx runnig on my host and configure it manually. And for jupyter container I had settings like this:

server {
    root /var/www/myside.com/html;
    index index.html index.htm index.nginx-debian.html;

   server_name lab.mysite.com;


listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myside.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myside.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    location  / {
            proxy_pass http://127.0.0.1:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
            proxy_read_timeout 86400;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Everything worked fine, when the host was running nginx. But with npm, I can’t figure out how to connect to the lxd container or how to redirect to the lxd container. I tired with containers own ip and host own ip, but no.
What might be blocking the connetion?

Your LXD proxy device ju_lxd will be listening on 127.0.01: 5000 on your LXD host.
It will forward connections to that port into your LXD container to 127.0.0.1:5000 inside the container.

You are then running NPM inside a docker container (which itself has its own network namespace which will provide its own 127.0.0.1 address), so configuring NPM to connect to 127.0.0.1:5000 will not connect to your LXD host’s 127.0.0.1:5000 port but instead the 127.0.0.1:5000 inside your NPM docker container (think of them like separate machines connected).

I’m not super familiar with docker, but assuming the NPM container can make outbound connections to your LXD host then you could setup the LXD proxy device to listen on a different IP that is still local to your LXD host but is not 127.0.0.1. Do you use a lxdbr0 bridge? If so you could get your LXD proxy device to listen on that IP, and then have the docker NPM connect to that.

Can’t figure out. Didn’t know about lxdbr0, looks like I’m using it.
So my lxdbr0 ip is 10.13.247.1 and containers ip is 10.13.247.114.
So tired to add new network for container like this:
lxc config device add ju_lxd port5003 proxy listen=tcp:10.13.247.114:5003 connect=tcp:127.0.0.1:5000
But you can’t listen that . (wrong idea?)
Then tired this:
lxc config device add ju_lxd port5003 proxy listen=tcp:10.13.247.1:5003 connect=tcp:127.0.0.1:5000 And it let my create one. Great.
But when I forward npm to 10.13.247.15003, nothing happens…Made second
bridge, but I don’t know how to add my container to that…

Looks like you got the ip and port merged in npm

10.13.247.15003,

10.13.247.1:5003*

Why don’t you just get npm to connect to 10.13.247.114 and remove the proxy device?

You’ll need to make sure the target service isn’t just listening on 127.0.0.1 though.

Finally.
I did remove all the devices. Made jupyter listen 10.13.247.114:5000. Set npm re-direct to https://10.13.247.114:5000. Still nothing. I was like “this should work!!! Why Why??” Then I tired one more thing. Change https to http and it worked…
I thing it would even work with devices…
Well now I learned what is lxdbr0 ( maybe) and how to add and remove devices from lxd container. Thanks.

1 Like