Planta Milenio ships with development defaults that must be hardened before the application handles real plant operations traffic. This guide walks through the required settings changes, static file collection, and the recommended way to serve the application using Gunicorn — optionally behind an Nginx reverse proxy managed by a systemd service.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/JuanDiego3030/Planta_Milenio/llms.txt
Use this file to discover all available pages before exploring further.
Pre-deployment checklist
Complete every step below before starting Gunicorn in a production environment.Rotate the secret key
Replace the default Paste the output as the new value of
SECRET_KEY in proyecto/settings.py with a cryptographically random value. You can generate one with Python:SECRET_KEY. Never commit a real secret key to version control.Disable debug mode
In This prevents Django from rendering detailed error tracebacks to end users and disables several insecure development conveniences.
proyecto/settings.py, change:Set ALLOWED_HOSTS
Replace the wildcard with your server’s actual IP address or hostname:Django will reject requests whose
Host header does not match an entry in this list, protecting against HTTP Host header attacks.Collect static files
Run Confirm the reported file count looks reasonable before proceeding.
collectstatic to copy every static asset from the assets/ directory and all installed apps into STATIC_ROOT, where Nginx (or another web server) can serve them directly:Apply pending migrations
Ensure the local SQLite database is up to date:This only touches the
default SQLite database. See Database Setup for details on the SQL Server connections.Running with Gunicorn
With the pre-deployment checklist complete, start the application using Gunicorn, which is included inrequirements.txt:
--workers 2 is appropriate for a low-concurrency internal plant operations tool. If you observe request queuing under heavier load, increase the worker count — a common formula is (2 × CPU cores) + 1. The WSGI entry point proyecto.wsgi:application corresponds to the WSGI_APPLICATION setting in proyecto/settings.py.
WeasyPrint (used for PDF report generation) requires Pango and Cairo system libraries. On Ubuntu/Debian, install them before starting Gunicorn:Without these libraries, any view that renders a PDF will raise a runtime error regardless of whether WeasyPrint itself is installed.
Nginx reverse proxy (recommended)
Running Gunicorn behind Nginx allows Nginx to serve static files directly from disk — bypassing Python entirely — and to handle TLS termination, connection buffering, and request rate limiting. Create a new site configuration file (for example/etc/nginx/sites-available/planta_milenio) with the following content:
/path/to/Planta_Milenio/static/ with the absolute path to the STATIC_ROOT directory produced by collectstatic. Enable the site and reload Nginx:
127.0.0.1 only (not 0.0.0.0) so the application port is not exposed directly to the network.
Systemd service
A systemd unit file keeps Gunicorn running across reboots and restarts it automatically if it crashes. Create/etc/systemd/system/planta_milenio.service:
/path/to/Planta_Milenio with the absolute path to the project root and /path/to/venv with the absolute path to the virtual environment. Enable and start the service:
journalctl -u planta_milenio -f to tail live logs from the Gunicorn process.