Giter VIP home page Giter VIP logo

nginx-proxy-avahi-helper's Introduction

nginx-proxy-avahi-helper

A docker container to generate mDNS CNAME entries for the virtual hosts used by jwilder/nginx-proxy.

The virtual hosts are held in the VIRTUAL_HOST Env Var of the proxied container.

Installing

docker pull hardillb/nginx-proxy-avahi-helper

Currently there are AMD64 and ARM64 based builds.

Running

To work this needs the following 2 volumes mounting:

-v /var/run/docker.sock:/tmp/docker.sock

This allows the container to monitor docker

-v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket

And this allows the container to send d-bus commands to the host OS's Avahi daemon

docker run -d -v /var/run/docker.sock:/tmp/docker.sock -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket hardillb/nginx-proxy-avahi-helper

AppArmor

If you are running on system with AppArmor installed you may get errors about not being able to send d-bus messages. To fix this add --privileged to the command line.

This is a temp workaround until I can work out a suitable policy to apply.

Acknowledgment

This uses and borrows heavily from mdns-publisher

nginx-proxy-avahi-helper's People

Contributors

hardillb avatar techiebod avatar timemachine3030 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nginx-proxy-avahi-helper's Issues

AppArmour issues on Mate Linux

cname.1     | Traceback (most recent call last):
cname.1     |   File "cname.py", line 93, in <module>
cname.1     |     main()
cname.1     |   File "cname.py", line 74, in main
cname.1     |     publisher = AvahiPublisher(30)
cname.1     |   File "/usr/local/lib/python3.8/site-packages/mpublisher/mpublisher.py", line 45, in __init__
cname.1     |     self.bus = dbus.SystemBus(private=True)
cname.1     |   File "/usr/local/lib/python3.8/site-packages/dbus/_dbus.py", line 195, in __new__
cname.1     |     return Bus.__new__(cls, Bus.TYPE_SYSTEM, mainloop=mainloop,
cname.1     |   File "/usr/local/lib/python3.8/site-packages/dbus/_dbus.py", line 102, in __new__
cname.1     |     bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
cname.1     |   File "/usr/local/lib/python3.8/site-packages/dbus/bus.py", line 124, in __new__
cname.1     |     bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
cname.1     | dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (inactive) interface="org.freedesktop.DBus" member="Hello" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
cname.1     | Exception ignored in: <function AvahiPublisher.__del__ at 0x7fd4c5936310>
cname.1     | Traceback (most recent call last):
cname.1     |   File "/usr/local/lib/python3.8/site-packages/mpublisher/mpublisher.py", line 62, in __del__
cname.1     |     self.bus.close()
cname.1     | AttributeError: 'AvahiPublisher' object has no attribute 'bus'

Is the container supposed to immediately quit?

I'm attempting to use this to organize services on my home server, but when I run the container:

2023-02-27 14:49:19 forego     | starting dockergen.1 on port 5000
2023-02-27 14:49:19 forego     | starting cname.1 on port 5100
2023-02-27 14:49:19 cname.1    | Traceback (most recent call last):
2023-02-27 14:49:19 forego     | starting cname.1 on port 5200
2023-02-27 14:49:19 forego     | sending SIGTERM to dockergen.1
2023-02-27 14:49:19 forego     | sending SIGTERM to cname.1

org.freedesktop.Avahi.NotSupportedError error

Any thoughts on this error?

forego      | starting cname.1 on port 17100
cname.1     | Traceback (most recent call last):
cname.1     |   File "/usr/src/app/cname.py", line 93, in <module>
cname.1     |     main()
cname.1     |   File "/usr/src/app/cname.py", line 81, in main
cname.1     |     status = publisher.publish_cname(cname, True)
cname.1     |   File "/usr/local/lib/python3.9/site-packages/mpublisher/mpublisher.py", line 117, in publish_cname
cname.1     |     group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), cname.encode("ascii"),
cname.1     |   File "/usr/local/lib/python3.9/site-packages/dbus/proxies.py", line 72, in __call__
cname.1     |     return self._proxy_method(*args, **keywords)
cname.1     |   File "/usr/local/lib/python3.9/site-packages/dbus/proxies.py", line 141, in __call__
cname.1     |     return self._connection.call_blocking(self._named_service,
cname.1     |   File "/usr/local/lib/python3.9/site-packages/dbus/connection.py", line 634, in call_blocking
cname.1     |     reply_message = self.send_message_with_reply_and_block(
cname.1     | dbus.exceptions.DBusException: org.freedesktop.Avahi.NotSupportedError: Not supported

Can't find host

Hi! Thanks for putting this together. I have everything running, but can't ping or otherwise resolve the hosts from other machines. I'm very new to mdns, so I'm not sure what to look for or how to interpret what I have found.

avahi-helper log:

dockergen.1 | 2022/04/03 16:52:54 Received event die for container 94a004be6d7e
dockergen.1 | 2022/04/03 16:52:55 Received event stop for container 94a004be6d7e
dockergen.1 | 2022/04/03 16:52:55 Generated 'cnames' from 7 containers
dockergen.1 | 2022/04/03 16:52:55 Running '/usr/src/app/restart.sh'
cname.1    | INFO: Exiting on SIGTERM...
dockergen.1 | 2022/04/03 16:52:55 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
forego     | starting cname.1 on port 5200
forego     | sending SIGTERM to dockergen.1
forego     | sending SIGTERM to cname.1
dockergen.1 | 2022/04/03 16:52:56 Received signal: terminated

Let's say one of those virtual hosts is test.local.

$ hostname
pi
$ avahi-resolve -n pi.local
pi.local     172.23.0.1
$ avahi-resolve -nv6 pi.local
Server version: avahi 0.7; Host name: pi.local
pi.local     fe80::c401:bdff:fe96:af0f
$ avahi-resolve -n test.local
pi.local     fe80::c401:bdff:fe96:af0f
$ avahi-resolve -n4 test.local
Failed to resolve host name 'test.local': Timeout reached

Note that the hostname and the virtual host resolve to the same v6 ip address, but the virtual host fails to resolve a v4 version. Not sure if that's significant or an issue.

On another machine:

$ ping test.local
Ping request could not find host test.local. Please check the name and try again.

$ ping pi.local

Pinging pi [192.168.68.64] with 32 bytes of data:
Reply from 192.168.68.64: bytes=32 time=5ms TTL=64
...

Where should I go from here? Thanks!

502 Bad Gateway

Hey, I've been using your helper for a few weeks and it was working great. Thanks for sharing it!

Recently however, editing or creating new *.local URLs stopped working and I get the following message when I try to access them:

502 Bad Gateway
nginx/1.19.3

My older *.local URLs that I haven't edited recently remain working though.

Here's the tail of the log file from nginx-proxy-avahi-helper (sha256:b73c58fa9edc43df63b934a22889344a204069eb9d449b6aa043fa9c396c1b50, Created | 2020-10-06 02:01:14 )

today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Received event die for container ee889cabfcd8
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Received event stop for container ee889cabfcd8
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Generated 'cnames' from 11 containers
today at 10:39 AM cname.1 | INFO: Exiting on SIGTERM...
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
today at 10:39 AM forego | starting cname.1 on port 5200
today at 10:39 AM forego | sending SIGTERM to cname.1
today at 10:39 AM forego | sending SIGTERM to dockergen.1
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Received signal: terminated
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Received signal: terminated
today at 10:39 AM
today at 10:39 AM forego | starting dockergen.1 on port 5000
today at 10:39 AM forego | starting cname.1 on port 5100
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Watching docker events
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
today at 10:39 AM cname.1 | INFO: All CNAMEs published
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:29 Received event start for container 5fbff26b8d87
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:29 Generated 'cnames' from 12 containers
today at 10:40 AM cname.1 | INFO: Exiting on SIGTERM...
today at 10:40 AM forego | starting cname.1 on port 5200
today at 10:40 AM forego | sending SIGTERM to dockergen.1
today at 10:40 AM forego | sending SIGTERM to cname.1
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:30 Received signal: terminated
today at 10:40 AM
today at 10:40 AM forego | starting dockergen.1 on port 5000
today at 10:40 AM forego | starting cname.1 on port 5100
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:31 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:31 Watching docker events
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:31 Contents of cnames did not change. Skipping notification '/usr/src/app/restart.sh'
today at 10:40 AM cname.1 | INFO: All CNAMEs published

And here's the tail of the log from nginx-proxy for the same time period (sha256:5e6f392e99e5454851caa8a3dbb021560a32375edff772b64f862c4d7831d038 Created 2020-10-30 09:46:00):

today at 10:38 AM Custom dhparam.pem file found, generation skipped
today at 10:38 AM forego | starting dockergen.1 on port 5000
today at 10:38 AM forego | starting nginx.1 on port 5100
today at 10:38 AM dockergen.1 | 2020/11/03 18:38:28 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:38 AM dockergen.1 | 2020/11/03 18:38:28 Watching docker events
today at 10:38 AM dockergen.1 | 2020/11/03 18:38:28 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Received event die for container ee889cabfcd8
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Received event stop for container ee889cabfcd8
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Generated '/etc/nginx/conf.d/default.conf' from 11 containers
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Running 'nginx -s reload'
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:26 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Received event die for container 2dadf9c97119
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Received event start for container 2dadf9c97119
today at 10:39 AM dockergen.1 | 2020/11/03 18:39:27 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:29 Received event start for container 5fbff26b8d87
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:29 Generated '/etc/nginx/conf.d/default.conf' from 12 containers
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:30 Received event die for container 2dadf9c97119
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:30 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:31 Received event start for container 2dadf9c97119
today at 10:40 AM dockergen.1 | 2020/11/03 18:40:31 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
today at 10:40 AM nginx.1 | 2020/11/03 18:40:41 [error] 42#42: *1 no live upstreams while connecting to upstream, client: 172.18.0.1, server: twldev.local, request: "GET / HTTP/1.1", upstream: "http://twldev.local/", host: "twldev.local"
today at 10:40 AM nginx.1 | twldev.local 172.18.0.1 - - [03/Nov/2020:18:40:41 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15"
today at 10:40 AM nginx.1 | 2020/11/03 18:40:41 [error] 42#42: *2 no live upstreams while connecting to upstream, client: 172.18.0.1, server: twldev.local, request: "GET /favicon.ico HTTP/1.1", upstream: "http://twldev.local/favicon.ico", host: "twldev.local", referrer: "http://twldev.local/"
today at 10:40 AM nginx.1 | twldev.local 172.18.0.1 - - [03/Nov/2020:18:40:41 +0000] "GET /favicon.ico HTTP/1.1" 502 157 "http://twldev.local/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15"

Any idea what is going on and how I could fix things?
Thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.