server icon indicating copy to clipboard operation
server copied to clipboard

Configure the server to listen on a unix socket

Open gustavgenberg opened this issue 5 years ago • 5 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like A way of configuring the server to listen on a unix socket. For example you could join the listenaddr and the port into a single option called listen. Then the listen option could either get passed localhost:1234 or unix:/tmp/gotify.sock.

Describe alternatives you've considered n/a

Additional context n/a

gustavgenberg avatar Nov 05 '19 00:11 gustavgenberg

Do you have a specific use-case for this? This would be a breaking change which would require manual intervention of the user.

jmattheis avatar Nov 05 '19 18:11 jmattheis

I am currently running many different applications behind an nginx reverse proxy. By having the applications listen on a unix socket, I do not have to deal with a ton of different ports (aswell as there is a tiny performance gain). Therefore using the same structure for Gotify makes sense to me.

Maybe the listen option could override the listenaddr and port options, thus making the update backwards-compatible.

gustavgenberg avatar Nov 05 '19 19:11 gustavgenberg

I would also like that for cleaner connection with nginx

sik0vny avatar May 05 '20 15:05 sik0vny

I also have this situation. I use nginx to handle ssh stuff and reverse proxy gotify.

schneidersoft avatar Oct 18 '20 12:10 schneidersoft

I'd also be happy if this was implemented. When running multiple applications behind a reverse proxy it is often much nicer to be able to proxy to a unix socket instead of having to pick a random port and hope some other service doesn't try to start listening on the same port. Using a socket like unix:/run/gotify/gotify.sock is much more unique that say port 8080

jerrykan avatar Jun 01 '21 14:06 jerrykan

Hey all 👋🏻

I thought I just drop my use case in here if it helps as I know the issue been open a long time.

I am Gotify within a Docker container and want to make sure that the networks are separated on the Host. So currently I am attaching the a gotify container to all networks to allow container within the network to push messages. However, an easier way could be to create a unix socket and then mount that as a volume within each container than the TCP overhead will be removed.

Thanks for reading the general idea, I am wiling to look into implementing this, however, cause the issue age I would like to know if the maintainer would want it 👍🏻

LaurenceJJones avatar Jan 14 '24 22:01 LaurenceJJones

@LaurenceJJones Yes, contributions for this are welcome. I'd say we make this configurable via server.listenaddr and server.ssl.listenaddr. If the value starts with unix: then a socket will be created. E.g.

server:
  keepaliveperiodseconds: 0 # 0 = use Go default (15s); -1 = disable keepalive; set the interval in which keepalive packets will be sent. Only change this value if you know what you are doing.
  listenaddr: "unix:/var/run/gotify-server.sock"
  # ... 

jmattheis avatar Jan 15 '24 18:01 jmattheis

Thank you for responding fast and with the idea of the implementation you would like to see. Since implementing this I would like to know if #554 is also on the cards, as using a unix socket without this option your logs have empty remote IP

2024-01-16T07:52:15Z | 200 |     304.232µs |                 | GET      "/"
2024-01-16T07:52:15Z | 200 |    9.572077ms |                 | GET      "/static/css/2.0f3898ba.chunk.css"
2024-01-16T07:52:15Z | 200 |   10.613353ms |                 | GET      "/static/js/main.b292f66c.chunk.js"
2024-01-16T07:52:15Z | 200 |   31.441821ms |                 | GET      "/static/js/2.f78cef81.chunk.js"
2024-01-16T07:52:15Z | 200 |    4.012945ms |                 | GET      "/current/user"
2024-01-16T07:52:15Z | 200 |      47.044µs |                 | GET      "/static/media/roboto-latin-400.176f8f5b.woff2"
2024-01-16T07:52:15Z | 200 |      27.858µs |                 | GET      "/static/media/roboto-latin-500.f5b74d7f.woff2"
2024-01-16T07:52:15Z | 200 |      50.595µs |                 | GET      "/static/favicon-196x196.png"
2024-01-16T07:52:15Z | 200 |      13.177µs |                 | GET      "/static/favicon-16x16.png"
2024-01-16T07:52:15Z | 200 |     160.358µs |                 | GET      "/stream?token=[masked]"
2024-01-16T07:52:15Z | 200 |     304.638µs |                 | GET      "/application"
2024-01-16T07:52:15Z | 200 |     332.621µs |                 | GET      "/message?since=0"

Gin has a way to set trusted IPs and which headers and I believe this modifies it already for the logger. Lets me know and I can work on this whilst you PR the former?

LaurenceJJones avatar Jan 16 '24 08:01 LaurenceJJones

Yeah, you can work on it. A setting with trusted ips sounds fine.

jmattheis avatar Jan 16 '24 19:01 jmattheis