This approach is fraught with problems for picking a port. How do you pick a random port that doesn't collide with an existing port in use? How do you prevent another application from acquiring that port between the time you pick the random port (and check that it is free) and the time you actually listen on it? I've hit both of these problems in practice. Specifying port 0 should be allowedby mfkilian - How to...
This may seem like an odd request but I have a situation where I want to start nginx and let linux assign the port that nginx listens on. I would have thought that listen 0 default_server; would allow this but alas, no. Is there a way to get nginx to allow linux to assign its port? (And please don't challenge why I want to do this...that's not up for debate :-) -- Mike Kilianby mfkilian - How to...