Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

Deploying web2py with Nginx and PostgreSQL: Should You Use Docker?

For production web2py, place Nginx and HTTPS in front, use uWSGI for the WSGI handoff, and keep PostgreSQL private and durable. Docker is optional: choose it for repeatable image-based operations, not as a substitute for backups, secrets, monitoring or database design.
Length8 min Posted Quest giverVGSources Team

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a production web2py service, use Nginx at the edge, uWSGI between Nginx and web2py, and PostgreSQL as a separately protected stateful service. Docker is optional. It improves repeatability when your team already builds and operates containers, but it does not solve database persistence, backups, secrets, upgrades, monitoring, or network security.

A conventional host installation follows the web2py manual most directly and usually involves fewer moving parts. A containerized deployment is sensible when image builds, Compose, or an orchestrator are already part of your operating model. In either case, keep PostgreSQL data outside disposable application layers, terminate HTTPS at Nginx, and document the exact Python and web2py versions you deploy.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The production request path

web2py is a WSGI application. Its built-in Rocket server has limited configuration capability, so the official deployment guidance places it behind a production web server such as Nginx. Nginx handles the public connection, TLS and static files; uWSGI passes dynamic requests to web2py using the uwsgi protocol; web2py uses PostgreSQL for application data.

The protocols matter. WSGI is the Python application interface, while uwsgi is the protocol Nginx uses to talk to uWSGI. They are related but not interchangeable: Nginx needs the uWSGI adapter and the matching uwsgi_params settings. A typical flow is:

Client --HTTPS--> Nginx --uwsgi socket--> uWSGI --WSGI--> web2py --TCP/SSL--> PostgreSQL

Keeping the database as a separate service makes its lifecycle explicit. It may run on another host, on a managed database platform, or in a dedicated database container, but it should not be treated as an ephemeral part of the web container.

Check the web2py lifecycle before choosing an installation model

The project overview states that web2py 2.27.1 is the last release supporting Python 2.7. web2py 3.x supports Python 3.9 and newer and is in limited maintenance mode; the project recommends moving to its successor, py4web. That status does not prevent an existing web2py application from being deployed, but it changes the risk calculation for a new system.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before building an image or provisioning servers, record:

  • The web2py release and application commit.
  • The Python major and minor version.
  • The uWSGI and Nginx versions supplied by your operating system or image.
  • The PostgreSQL major version and the Python PostgreSQL adapter version.
  • Operating-system package versions or immutable image digests.

Pin those choices in the deployment repository. Recheck compatibility before upgrades, especially when a base image or distribution moves to a newer Python release. Limited maintenance also means you should evaluate whether py4web is a better target for a new project rather than assuming a long stream of web2py updates.

Option 1: a conventional host installation

This approach installs Nginx, uWSGI and web2py on the application host and PostgreSQL on a managed disk or separate database host. It follows the official recipe without adding a container runtime or image registry.

1. Install the service components

Use your distribution’s supported packages for Nginx, uWSGI, Python and the PostgreSQL client adapter. Install PostgreSQL from the distribution package or use a separately managed PostgreSQL service. Package names and uWSGI plugin names differ by distribution, so verify that the installed uWSGI build includes the Python version your web2py release requires.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Create the database and least-privilege account

Create a database owned by an application-specific role rather than using a superuser. The web2py manual uses port 5432 as PostgreSQL’s conventional port and illustrates a DAL connection like this:

db = DAL("postgres://myuser:mypassword@localhost:5432/mydb")

In production, do not commit a real password in source code. Supply credentials through a protected environment mechanism or a secret store, restrict the role’s privileges to the required database, and use TLS when the database is reached over a network. If PostgreSQL is on another host, replace localhost with an internal name or address and enforce a database firewall policy that admits only the application tier.

3. Configure PostgreSQL maintenance

Enable PostgreSQL’s autovacuum. It reclaims obsolete row versions and helps tables and indexes remain usable as data changes. Set retention and backup policies separately; autovacuum is not a backup.

4. Run web2py through uWSGI

Configure uWSGI to load the web2py WSGI application and listen on a Unix socket. A Unix socket keeps the application protocol off the public network and lets Nginx hand requests to a local endpoint. Set process counts, timeouts, user permissions and log destinations according to your workload and operating-system service manager. Ensure the socket directory is writable by uWSGI and readable by the Nginx worker user; a permission mismatch produces immediate gateway errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Add the Nginx server block

The English web2py Nginx example creates /etc/nginx/sites-available/web2py. Its pattern is:

  • Define a server block for the public hostname.
  • Serve web2py application static files directly from Nginx.
  • Include uwsgi_params for dynamic requests.
  • Pass dynamic traffic to unix:///tmp/web2py.socket (or the socket path you configured in uWSGI).

Keep static-file locations ahead of the dynamic catch-all so assets do not consume Python workers. Test the configuration with your distribution’s Nginx validation command before reloading. If Nginx reports a missing socket, check that uWSGI started successfully and that both services agree on the exact path.

6. Terminate HTTPS at Nginx

Add the TLS server block shown by the manual’s pattern, supplying the certificate and private-key paths issued for your hostname. Redirect clear-text HTTP to HTTPS, restrict access to administrative endpoints, and never expose web2py’s admin or appadmin interfaces without HTTPS. Keep the private key readable only by the account that needs it and renew certificates before expiry.

7. Separate service lifecycles

Run Nginx, uWSGI and PostgreSQL as independently supervised services. This lets you restart the application without restarting the database, inspect each log stream, and roll back one component when an upgrade fails. The manual advises placing the web server and database on different machines when practical, connected by a secure internal network or SSL tunnel.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option 2: Dockerizing the stack

Docker is a packaging and process-isolation choice, not a deployment architecture by itself. A sensible container design keeps the concerns visible:

  • Nginx container: public ports, TLS certificates, static files and reverse-proxy configuration.
  • web2py/uWSGI container: the pinned Python runtime, application code and uWSGI configuration.
  • PostgreSQL service: a managed database or a dedicated database container with durable storage and a tested backup process.

A Docker Hub listing demonstrates a minimal image that combines Nginx and web2py for production, but the available material does not establish a maintained tag, security policy, Compose file, PostgreSQL compatibility matrix or health checks. Treat such an image as an example to inspect, not as an automatic production dependency. Prefer a reproducible Dockerfile that pins a base image digest, installs only required packages, runs as a non-root user where feasible, and records the source commit.

What Docker improves

  • Repeatability: the same image can be tested and promoted through environments.
  • Isolation: application dependencies are separated from host packages.
  • Rollback: a previously built image can be redeployed if the new release fails.
  • Team consistency: Compose or an orchestrator can describe networks, environment variables and service dependencies.

What Docker does not remove

  • PostgreSQL data must live on a durable volume or external service, never only in a disposable container layer.
  • Backups still need scheduling, retention, encryption and restore drills.
  • Secrets still need controlled injection and rotation; putting passwords in an image or committed Compose file is unsafe.
  • Health checks, startup ordering, resource limits, log retention and alerting still need explicit configuration.
  • Nginx, uWSGI, Python and PostgreSQL upgrades still require compatibility testing.

If you cannot answer where the database volume resides, how it is restored to a clean environment, and how a failed image is rolled back, the container design is not production-ready.

Docker versus host installation

Decision area Conventional host Docker-based deployment
Repeatability Achieved through package and configuration management; drift must be controlled. Image builds capture dependencies; image tags or digests must be pinned.
Database state Managed disk or dedicated database host is straightforward. Requires an explicitly durable volume or external PostgreSQL service.
Operations Uses the operating system’s service manager, logs and monitoring. Requires container health checks, orchestration, log collection and resource limits.
Security boundary Host firewall and filesystem permissions are familiar but must be maintained. Networks and secrets are declarative, but a misconfigured published port can expose services.
Upgrades and rollback Package upgrades can affect shared host libraries. Image replacement is clean, provided database migrations and rollback plans are compatible.
Best fit Teams wanting the official recipe and simple service topology. Teams already operating CI image builds, Compose or an orchestrator.

Neither column is inherently safer. The safer choice is the one your team can patch, observe, back up and restore reliably.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Network and security controls

  • Public edge: expose only Nginx’s HTTPS listener. Keep uWSGI sockets and PostgreSQL off public interfaces.
  • Administrative access: put web2py administrative endpoints behind HTTPS and an additional network or identity control where possible.
  • Database authentication: use a dedicated role, a strong secret and encrypted transport for remote connections. Do not copy illustrative trust authentication settings into an internet-facing deployment without reviewing them.
  • Least privilege: grant the application only the database permissions it needs; reserve schema changes and superuser operations for controlled deployment jobs.
  • Secrets: keep TLS keys, database passwords and signing material outside source control and container layers.
  • Updates: track security updates for the operating system, Python runtime, Nginx, uWSGI and PostgreSQL, while checking web2py compatibility.

Backups, recovery and observability

Schedule PostgreSQL logical backups with pg_dump and practice restores with pg_restore. A successful backup job is not proof of recoverability: periodically restore to an isolated PostgreSQL instance, verify schema and representative application data, and record the elapsed recovery time.

Monitor the boundaries where failures appear:

  • Nginx HTTP status rates, TLS expiry and request latency.
  • uWSGI worker health, queue depth, timeouts and restart counts.
  • PostgreSQL connection exhaustion, disk growth, replication or managed-service alerts, and autovacuum activity.
  • Filesystem or volume capacity for uploads, logs and database data.

Define log retention before traffic arrives. In containers, send logs to the platform’s collector rather than allowing an unbounded JSON log file to fill the host.

Troubleshooting by symptom

502 Bad Gateway from Nginx

Confirm that uWSGI is running, the socket path exactly matches the Nginx uwsgi_pass value, and filesystem permissions allow Nginx to connect. Then inspect the uWSGI log for import errors or a Python-version mismatch.

Static files return 404 while dynamic pages work

Check the Nginx static alias or root path, file ownership and the URL prefix used by the web2py application. Test a known asset directly; do not route every asset through Python as a first workaround.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

web2py cannot connect to PostgreSQL

Verify hostname, port 5432 (unless intentionally changed), database name, role credentials and PostgreSQL’s network access rules. From the application environment, test DNS and TCP reachability, then inspect PostgreSQL authentication logs. For a remote database, confirm that TLS requirements and certificate trust settings agree on both sides.

Container starts, then exits

Read the container’s first error rather than repeatedly restarting it. Common causes are a missing secret, an invalid uWSGI module path, a migration failure or a dependency built for a different Python version. Add a health check that tests the actual application path and database readiness, not merely that a process exists.

A practical decision rule

Choose the host installation when you want the shortest path from the web2py manual, have administrators comfortable with system packages, and can manage configuration and backups centrally. Choose Docker when your existing delivery pipeline already produces pinned images, your operators understand persistent volumes and health checks, and you need repeatable promotion or rollback across environments.

For either choice, start with a small staging deployment that mirrors production networking. Exercise HTTPS, static files, admin restrictions, database migrations, backup restoration and a failed application restart before accepting public traffic. Keep the architecture boring: Nginx at the edge, uWSGI for the WSGI handoff, private PostgreSQL, explicit secrets and documented recovery steps.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.