Automatic Port Assingment


can anyone help me to automated my stack deployment?

Currently I have a List where I write down Ports I use.

As example:

wordpress tcp 8080
docuwiki tcp 8081
Jira tcp 8082

then I write my reverse proxy conf for each stack:

server {
listen 443 ssl;
resolver valid=5s;
ssl_certificate /etc/nginx/certs/wildcard.crt;
ssl_certificate_key /etc/nginx/certs/wildcard.key;

location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port 8090;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $upstream “”;
proxy_pass http://$upstream;
proxy_http_version 1.1;
client_max_body_size 10M;


I realy would like to automate this. so I don’t have to make a list with used ports and don’t have to write each time config files for nginx.

Any idea how I could do this?