2

Is there a way to serve a webpage from a locally running tcp server listening on a unix domain socket instead of localhost:<port>?

something like:

file:///tmp/webpage.sock

my only real motivation is to avoid port conflicts in the 2000-5000 range.

1

Yes

It is easy to serve it.

No

But harder to get the client to use it.

An alternative

However because you told me why you are doing it, I have another solution.

You want several web-servers to serve to only the local machine, but not have conflicts of port. It may also be nice if they all used the same port number.

Loopback addresses are 127.0.0.0/8 That is 127.x.x.x not just 127.0.0.1.

Therefore use a different IP address for each server. E.g. 127.0.0.2, 127.0.0.3 ...

| improve this answer | |
  • cool, I can try the other loopback addresses. Could you add an example of using unix sockets as well? just curious how it would work. – Alexander Mills Mar 30 at 17:41
  • I don't know if the servers are programmed to do it. But you could listen on a high port, and use port forwarding. I just went for multiple loop-back addresses. – ctrl-alt-delor Mar 30 at 19:49
  • yeah the multiple loop back addresses is cool. will prob use that. but I am really curious how it could be done with unix domain sockets, any idea how? – Alexander Mills Mar 30 at 22:47
  • 1
    I would look at netcat. It may be able to forward it. ssh can do it but there is overhead of encryption. Both would need the server to listen on a socket, and would just forward from another unix socket. I think I did it once. But could not convince the browser to use it. I would ask another question. But be clear about what you are not asking for, and link to this question. – ctrl-alt-delor Mar 31 at 19:18
  • 1
    yeah but netcat would be listening on a port and then forwarding to the unix domain socket? ultimately I am trying to avoid listening on a port at all, so that defeats the purpose, but your original idea to use a different loopback address is good. – Alexander Mills Mar 31 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.