How I Set Up My Ubuntu Server for Apps
Published:
• Updated:
Your app works locally. Now let’s put it online.
Install Nginx
Nginx sits in front of your app and handles web traffic.
sudo apt install nginx -ysudo systemctl enable nginxSet Up Firewall
Only open what you need:
sudo ufw allow OpenSSHsudo ufw allow 'Nginx Full'sudo ufw enableGet Free SSL
For that lock icon in browsers:
sudo apt install certbot python3-certbot-nginx -ysudo certbot --nginx -d yoursite.comIt renews itself. Nice.
Connect Nginx to Your App
Create /etc/nginx/sites-available/myapp:
server { listen 443 ssl; server_name yoursite.com;
location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; }}Enable it:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginxKeep Your App Running Forever
Without this, your app dies when server restarts.
Create /etc/systemd/system/myapp.service:
[Unit]Description=My AppAfter=network.target
[Service]User=www-dataWorkingDirectory=/var/www/myappExecStart=/usr/bin/node server.jsRestart=on-failure
[Install]WantedBy=multi-user.targetStart it:
sudo systemctl enable myappsudo systemctl start myappWhen Things Break
sudo systemctl status myappsudo journalctl -u myapp -n 30Done
Nginx handles traffic, systemd keeps app alive, firewall blocks bad stuff, SSL keeps it safe. That’s it.