The point of having nginx in any kind of scenario is to be able to talk to it, so even if this should have to be a random port, you would like to know which one it is.
Therefore, you're free to have a script determining a random port in a given range, e.g,. between 8000/tcp and 8999/tcp, and substitute that with a bit of sed in your nginx.conf.template to produce an actual nginx.conf (or some sub-configuration for a server).
You may want to apply the same mechanism (maybe based on an envsubst) to change certificates, domain names, etc., based on the type of environment you're deploying to. I use that under Terraform to deploy nginx instances depending on the target environment's parameters.
--j.
Therefore, you're free to have a script determining a random port in a given range, e.g,. between 8000/tcp and 8999/tcp, and substitute that with a bit of sed in your nginx.conf.template to produce an actual nginx.conf (or some sub-configuration for a server).
You may want to apply the same mechanism (maybe based on an envsubst) to change certificates, domain names, etc., based on the type of environment you're deploying to. I use that under Terraform to deploy nginx instances depending on the target environment's parameters.
--j.