Wifi connect + Grafna port 80

Hi.

I am building a temperature monitoring probe with RPI 3+ B. I have an a container running Grafna and another running wifi-connect. Both these need to use port 80 ( I can’t get it working another way.) If allocate port 80 to wifi-connect in dockercompse then grafna stops being available and if I allocate port 80 to both of them . When I connect to capacitive portal to connect wifi grafna charts shows up. I have tried changing ports that doesn’t help. Sorry if this is a really stupid question

Port 80 inside the containers or outside them (on the Pi)? Having two listeners on the same host port will of course conflict, and wifi-connect will want network_mode: "host", which limits your port options in docker-compose (and there is no need to allocate port 80 to wifi-connect when it has host network access). However, wifi-connect does have an internal port setting that might let you free up port 80 on that end.

Alternatively, if grafana can run without host mode, then you could map a different external port to port 80 inside the container:

ports:
    # outside:inside
    - "3000:80"

The dashboard would then be available at [local address]:3000.

Hey @ausyp, welcome to the forums!

To add to what @mber said above, I would suggest mapping the internal ports 80 to whatever external ports you would like. Is there an issue running the following configuration?

version: '2.1'
services:
  grafana:
    image: grafana
   ports:
     - 3000:80
  wifi-connect:
    image: wifi-connect
    network_mode: host
    privileged: true
    labels:
      io.balena.features.dbus: '1'
      io.balena.features.firmware: '1'

Something like the above will allow you to connect to Grafana on port 3000 while wifi-connect can still operate on port 80.

It worked thank you so much.

Would it be possible to expose port 3000 used by Grafana for the public URL. Or map 3000 to 80 just for public. Thanks in advance.

Unfortunately the public URL can only point to port 80 or 443 at this point, so with the wifi-connect block you won’t be able to use the Public URL for a Grafana service on port 80.

We are aware this is a friction point so we have been actively redesigning our Public URL backend for some time now in order to expose more than one service. There will likely be an announcement when we have updates.

Hi,

You might be able to setup a reverse proxy with nginx or similar to help with this (see for example here).

You could then have the URL <host>/grafana map to <grafana container>:80 and <host>/ to <wifi-connect container>:80
That way, by default you would land on your wifi-connect interface, but still have the option to go to Grafana.

1 Like

Thanks for sharing this workaround @TJvV i’m going to test it next week :slight_smile:

@TJvV Was able to setup a nginx but i am getting this error at the public url.

I used this nginx.conf

# http://docs.grafana.org/installation/behind_proxy/

events {}

http {
  server {
  listen 80;
  listen 443  ssl;
  root /usr/share/nginx/www;
  index index.html index.htm;
	
	
    # default path to wifi-connect
    location / {
      proxy_pass http://127.0.0.1:80;
    }
		
		# /grafana path
		location /grafana {
			proxy_set_header Host $http_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_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_pass http://127.0.0.1:3000;
    }
  
    # Proxy Grafana Live WebSocket connections.
    location /grafana/api/live {
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "Upgrade";
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:3000/;
   }    
  }
}

Was anyone able get it working ?
Thanks in advance

@Ausyp can you share your whole setup?
That will make it easier to see where things could go wrong (and optionally test things out locally).

At the very least we would need to see your Docker/Balena and Grafana configuration

Note that if your nginx runs in Docker/Balena and on the same network as Grafana, you could simply use the container name as host and port 80 and won’t need to use the exposed port 3000.
This (probably) isn’t your problem, but might be nice to keep in mind.

Edit: actually, the location / pointing to 127.0.0.1:80 could cause a routing loop that your server won’t like.

Hey @ausyp, as mentioned above you probably don’t want to point to 127.0.0.1 inside the nginx container, and should instead point to each service name :port. Something like this:

proxy_pass http://wifi-connect:80
proxy_pass http://grafana:3000

Note though that since wifi-connect has to run in host networking mode, your nginx service probably can’t listen on port 80. However port 443 should be fine.

Let us know how it works out!

1 Like

Hi @TJvV this is the github link: GitHub - ausyp/temptrack: Templogger using Belenasense 1.99.

I figured it out. Well somebody had already solved it.