//nbkelley /homelab

MBTA Dashboard - Setup

MBTA Dashboard - Setup#

What Was Established#

Office transit dashboard deployed on a self-hosted Debian VM (PLT-MBTADisplay, 192.168.168.42). Nginx serves static files from /var/www/MBTADisplay/public and proxies /api/ requests to a Node/Express caching proxy on port 3000. API keys are stored server-side and never exposed to the browser. Process managed via pm2 with a systemd service.

Architecture#

Browser (Anthias/Desktop)
    → Nginx (:80) → / → static files (/var/www/MBTADisplay/public)
                   → /api/ → Node/Express proxy (:3000)
                                → MBTA v3 API
                                → OpenWeatherMap API
                                → RSS feeds
                                → Caches responses

Nginx Configuration#

server {
    listen 80;
    server_name transit.intra.plgt.com 192.168.168.42;

    root /var/www/MBTADisplay/public;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location /api/ {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Node/Express Proxy#

Setup#

mkdir -p /opt/mbta-proxy
cd /opt/mbta-proxy
npm init -y
npm install express node-fetch

API Key Management#

  • API keys stored in /opt/mbta-proxy/.env
  • Loaded via process.env.MBTA_API_KEY in server.js
  • pm2 started with --env flag to load .env file
  • Critical: API key must survive server.js overwrites from GitHub syncs

pm2 Process Manager#

pm2 start server.js --name mbta-proxy
pm2 save
pm2 startup systemd

systemd Service (/etc/systemd/system/pm2-administrator.service)#

[Unit]
Description=PM2 process manager
After=network.target

[Service]
Type=forking
User=administrator
ExecStart=/usr/local/bin/pm2 resurrect
ExecReload=/usr/local/bin/pm2 reload all
ExecStop=/usr/local/bin/pm2 kill
Restart=on-failure

[Install]
WantedBy=multi-user.target

GitHub Deployment#

Repository#

  • Repo: https://github.com/bich-nguyen/MBTADisplay.git
  • Cloned to /var/www/MBTADisplay
  • Static files in public/ subdirectory
  • Server files in /opt/mbta-proxy/ (separate from web root)

Ownership#

sudo chown -R administrator:administrator /var/www/MBTADisplay

Note: www-data ownership breaks git operations from administrator user.

Web Server Stack (Nginx + Apache)

Web Server Stack (Nginx + Apache)#

What Was Established#

In this setup, Nginx is utilized as a high-performance reverse proxy to handle incoming traffic and static content, while Apache serves as the backend for dynamic content (e.g., PHP/WordPress) due to its flexible .htaccess support.

Key Decisions#

  • Architecture: Nginx acts as the entry point (Port 80/443) and proxies requests to Apache running on a non-standard port (e.g., 8080).
  • Rationale: Leverages Nginx’s superior concurrency and static content handling with Apache’s ease of use for per-directory configuration.

Current Configuration#

Apache Backend Configuration#

Modify /etc/apache2/ports.conf to listen on a different port to avoid conflict with Nginx:

Nginx vs Apache for Static Hosting

Nginx vs Apache for Static Hosting#

What Was Established#

A comparison of Nginx and Apache for the purpose of hosting static HTML/CSS/JS files within a Proxmox LXC or VM.

Key Decisions#

  • Choose Nginx if: You prioritize performance, low memory footprint, and plan to use it as a reverse proxy for modern stacks (Node.js, Python).
  • Choose Apache if: You require .htaccess support for per-directory configuration or are working with legacy PHP/LAMP stacks.

Current Configuration#

Nginx Basic Static Config#

server {
    listen 80;
    root /var/www/html;
    index index.html;
}

Apache Basic Static Config#

<VirtualHost *:80>
    DocumentRoot /var/www/html
    DirectoryIndex index.html
</VirtualHost>

Deployment Commands (LXC)#

To create a standard Ubuntu 22.04 LXC for web hosting:

Web Server Deployment Pattern (Beginner)

Web Server Deployment Pattern (Beginner)#

What Was Established#

For a beginner-friendly, lightweight, and scalable homelab setup, a stack consisting of Ubuntu Server LTS and Nginx is the recommended standard. This provides a balance of ease of use, extensive documentation, and low resource overhead.

Key Decisions#

  • Operating System: Ubuntu Server LTS (chosen for stability, community support, and ease of management).
  • Web Server: Nginx (chosen over Apache for being lightweight, faster for static content, and better suited for future use as a reverse proxy).
  • Resource Allocation (Small Site): 1-2 CPU cores, 1-2 GB RAM, 10-2/GB Disk.

Current Configuration#

Nginx Site Configuration#

Default root directory: /var/www/html