We have a port based multi tenancy. Right now we have a separate file in sites-available directory for each tenant. This is becoming cumbersome to manage as the number of tenants grow. Is there a better alternative to this? Each tenant has a separate sub domain.
We can maintain sub domain - port mapping either in db, or in redis. Would it be a better idea to keep it in redis and dynamically route it?
server {
server_name abc.mydomain.com;
location /{ proxy_pass http://localhost:7000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade;
}
}
I have ended up creating a template config file, and having a script generating the actual config files. In my case, it is a nodejs script that will loop through the projects directory, and create a config file for each directory in a config folder. This config folder location is "include"d in the nginx.conf.