Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support binding on port 0 #2992

Closed
allentian opened this issue Jan 20, 2020 · 7 comments
Closed

Support binding on port 0 #2992

allentian opened this issue Jan 20, 2020 · 7 comments
Labels
feature ⚙️ New feature or request
Milestone

Comments

@allentian
Copy link

Binding on port 0 means the kernel will select an unused port.
It seems Caddy does not support it.
Do you have plan to support it?
Thanks.

@francislavoie
Copy link
Member

Strange. Could you describe a use-case where this would be useful?

Which version of Caddy are you using? It's very unlikely a change to this would land in v1, but it's possible that it could be supported in v2.

@francislavoie francislavoie added the feature ⚙️ New feature or request label Jan 20, 2020
@allentian
Copy link
Author

Thanks for quick reply.
I hope to specify port 0 for Caddy server, then it can assign random unused port for use.
If I specify any number such as 55555 which is used by another process, I will get compaint like Listen: listen tcp 127.0.0.1:55555: bind: address already in use.
If I can speciy port 0 and caddy server helps to choose any unused port for use, I won't worry about such issue any more.

@francislavoie
Copy link
Member

I understand that, but why would you want to use a random port instead of a specific well-known port, especially for a webserver?

I think a random port does makes sense in a situation where you have some development tool, for example npm's built-in server, where you just need to spin something up for local usage. Is this the kind of situation you're thinking of?

More information about how and why this would be used would be helpful.

@mholt
Copy link
Member

mholt commented Jan 21, 2020

We can do this, but I also want to know a compelling use case.

@allentian
Copy link
Author

allentian commented Jan 21, 2020

Thanks for your response .
I have given the use case to you in the first reply.
It is only used for development instead of production.
For example another process is using port 55555.
If I choose 55555 as Caddy Server's port at the same time, I get complaint lit Listen: listen tcp 127.0.0.1:55555: bind: address already in use.
If I can specify port 0 and caddy server helps to choose any unused port, I won't have such issue.
I am not sure if it is a resonalble use case for you.
BTW, I am using Caddy v1.

@mholt
Copy link
Member

mholt commented Jan 22, 2020

Okay. No problem, but I think if there is enough demand for this feature, we should definitely do it.

@mholt mholt closed this as completed in 581f1de Apr 1, 2020
@mholt
Copy link
Member

mholt commented Apr 1, 2020

So, this already works actually. I just added a log message that prints the port so you can know it without having to netstat or whatever.

@mholt mholt added this to the v2.0.0-rc.1 milestone Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants