0

Assuming I will use gunicorn to mount a django application:

  1. How can I bind to both localhost:8000 AND to a unix socket?
  2. How can I distinguish whether the request (in a view) is coming from the unix socket?
Luis Masuelli
  • 12,079
  • 10
  • 49
  • 87

1 Answers1

1

You could use something like Gunicorn to listen on both a UNIX socket and a TCP port.

In order to distinguish between the two in your views, I'd simply run two processes - One that listens on the TCP port and one for the UNIX socket. When starting said process, specify an environment variable which you can later access in your view.

ozk
  • 2,025
  • 1
  • 15
  • 11
  • sounds good, and cleaner. I was planning to use gunicorn. how do I bind a unix socket with gunicorn? – Luis Masuelli Jan 23 '15 at 16:20
  • 1
    See this link: http://docs.gunicorn.org/en/latest/run.html?highlight=unix - basically just pass `unix:/path/to/socket` instead of the regular `host:port` syntax. – ozk Jan 23 '15 at 16:25