Create a Site that serves an app on a specific port
To create a site add a file to the sites enabled folder. Name it the DNS of your site.
server {
listen 80;
listen [::]:80;
server_name sub.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
Enable/Disable a site
To enable a site create a symbolic link:
ln -s /etc/nginx/sites-available/sub.example.com /etc/nginx/sites-enabled/sub.example.com
Then run
sudo service nginx restart
To disable a site simply delete the symbolic link:
rm /etc/nginx/sites-enabled/sub.example.com