CherryPy on Ubuntu 24.04 (Python + WSGI + Nginx + SSL)

CherryPy is a minimal yet powerful Python web framework that allows developers to build scalable web applications with a clean, object-oriented style. Unlike heavy frameworks such as Django or Flask, CherryPy focuses on being a lightweight HTTP server and web framework that lets you structure applications however you want, without forcing patterns or dependencies. Its simplicity, performance, and production-readiness make it a popular choice for small services, APIs, and embedded applications.

Running CherryPy on Ubuntu 24.04 LTS (Noble Numbat) ensures long-term stability, security, and modern system packages. With systemd 255, OpenSSL 3, and up-to-date Python 3.12, Ubuntu 24.04 is an ideal foundation for deploying production-grade CherryPy applications behind Nginx with SSL termination.


Architecture Overview

LayerComponentRole
OSUbuntu 24.04 LTSStable, secure Linux base with long-term support
RuntimePython 3.12 + venvRuns the CherryPy application in an isolated environment
FrameworkCherryPy (WSGI server)Lightweight Python framework and HTTP server
Process Managersystemd / PM2 (alt)Keeps CherryPy running, manages restarts and uptime
Reverse ProxyNginxTLS termination, compression, caching, request routing
TLSLet’s Encrypt / PKIProvides HTTPS security for the web application

Why Use CherryPy?

  • Minimal & fast – lightweight design with a built-in production-ready HTTP server.
  • Flexible – no enforced ORM or templating; integrate with any Python library.
  • Object-oriented – applications are structured as classes and methods.
  • Production-ready – stable since 2002, with built-in features like sessions, caching, and static file serving.
  • Embeddable – can run as part of larger Python projects or services.

CherryPy vs Other Python Frameworks

Feature/CapabilityCherryPyFlaskDjangoFastAPI
PhilosophyMinimal, server + frameworkMinimal, microframeworkFull-stack (batteries included)High-performance async APIs
HTTP serverBuilt-in WSGIRequires WSGI serverRequires WSGI serverASGI (uvicorn/gunicorn)
Learning curveEasyEasySteeperMedium
Best use caseSmall apps, APIsAPIs, prototypesLarge web appsAsync APIs, microservices

CherryPy excels when you want a simple, no-nonsense Python framework that runs fast without extra complexity.


Security & Best Practices

  • Always deploy CherryPy behind Nginx with HTTPS.
  • Run the app under a dedicated system user, not root.
  • Use virtual environments to isolate dependencies.
  • Enable systemd service management for uptime and auto-restarts.
  • Keep Python, CherryPy, and libraries updated with security patches.
  • Harden Nginx with security headers (HSTS, CSP, X-Frame-Options, etc.).

Typical Use Cases

  • Lightweight REST APIs for microservices.
  • Internal tools and dashboards where speed matters.
  • Embedded applications inside larger Python projects.
  • Prototyping small web apps before scaling to larger frameworks.
  • Secure services behind Nginx with SSL for production workloads.

Deploying CherryPy on Ubuntu 24.04 with Python, Nginx, and SSL gives you a fast, minimal, and secure Python web stack — ideal for developers who want flexibility and performance without the overhead of heavy frameworks.


Step 1: Create a Server Instance on Shape.Host

To get started, you need a clean Ubuntu 24.04 server. Here’s how to provision one on Shape.Host:

Log into your Shape.Host dashboard.

Click Create → Instance.

Shape.host Resources dashboard with Create > Instance highlighted.

Choose a data center location close to your users.

Shape.host instance form with the data center location selector highlighted.

Select a VPS plan with at least 2 CPUs, 2 GB RAM, and 20 GB SSD.

Under operating systems, choose Ubuntu 24.04 (64-bit).

Shape.host instance form with the operating system image selector highlighted.

Click Create Instance.

Shape.host instance form with the Create Instance button highlighted.

Copy your server’s public IP address from the Resources section.

Shape.host Resources dashboard with the server IP address highlighted.

Step 2: Connect to Your Server

  • Linux/macOS: ssh root@your_server_ip
  • Windows:
    Use PuTTY, enter your server IP, choose SSH, and log in with the root credentials provided by Shape.Host.

Step 3: Install Dependencies

Update packages and install Python, virtualenv, pip, and Nginx:

apt update
apt upgrade
apt install python3 python3-venv python3-pip nginx
Terminal showing APT package management commands and output.
Terminal showing APT package management commands and output.

Step 4: Create CherryPy User and Application Directory

adduser --system --group --no-create-home cherrypy
mkdir -p /opt/myapp

Creates a system user cherrypy (without a home directory) and a folder for the app.

Terminal showing Linux user account management commands.

Step 5: Set Up a Python Virtual Environment

python3 -m venv /opt/myapp/venv
/opt/myapp/venv/bin/pip install --upgrade pip
/opt/myapp/venv/bin/pip install cherrypy

Creates an isolated Python environment for CherryPy and installs the framework.

Terminal showing Python environment or package installation output.

Step 6: Create a Sample CherryPy App

cat >/opt/myapp/app.py <<'PY'
import cherrypy

class App:
    @cherrypy.expose
    def index(self):
        return "Hello from CherryPy behind Nginx!"

def main():
    cherrypy.config.update({
        "server.socket_host": "127.0.0.1",
        "server.socket_port": 8000,
        "engine.autoreload.on": False
    })
    cherrypy.quickstart(App(), "/")

if __name__ == "__main__":
    main()
PY

This app responds with a simple “Hello from CherryPy behind Nginx!” when accessed.


Step 7: Set Permissions

chown -R cherrypy:cherrypy /opt/myapp

Ensures the cherrypy user owns the app directory.

Terminal showing file ownership or permission commands.

Step 8: Create a Systemd Service

cat >/etc/systemd/system/cherrypy.service <<'UNIT'
[Unit]
Description=CherryPy WSGI App
After=network.target

[Service]
Type=simple
User=cherrypy
Group=cherrypy
WorkingDirectory=/opt/myapp
Environment=PATH=/opt/myapp/venv/bin
ExecStart=/opt/myapp/venv/bin/python /opt/myapp/app.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
UNIT
Terminal showing a systemd service unit configuration.

Reload systemd and enable the service:

systemctl daemon-reload
systemctl enable cherrypy
systemctl start cherrypy

CherryPy now runs in the background as a managed service.

Terminal showing systemd service management commands or output.

Step 9: Configure Nginx as Reverse Proxy

cat >/etc/nginx/sites-available/myapp <<'NGINX'
server {
    listen 80;
    server_name example.com;

    client_max_body_size 20M;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Connection "";
        proxy_read_timeout 300;
    }

    access_log /var/log/nginx/myapp_access.log;
    error_log  /var/log/nginx/myapp_error.log;
}
NGINX
Terminal showing web server configuration text.

Enable the site and reload Nginx:

ln -sf /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx

Now requests to http://example.com will be proxied to CherryPy running on port 8000.

Terminal showing systemd service management commands or output.

Step 10: Secure with SSL (Let’s Encrypt)

apt install certbot python3-certbot-nginx
certbot --nginx -d example.com

This automatically fetches and installs a free SSL certificate.

Terminal showing APT package management commands and output.
Terminal showing Certbot certificate commands and messages.

Now visit:

https://example.com/

You should see:
Hello from CherryPy behind Nginx!

Browser displaying the CherryPy greeting behind Nginx.

You’ve successfully deployed CherryPy on Ubuntu 24.04 using systemd and Nginx as a reverse proxy, with SSL enabled via Let’s Encrypt. This setup is lightweight, production-ready, and easy to extend for larger projects.

For scalability and performance, run your CherryPy applications on Shape.Host Cloud VPS — offering high-speed infrastructure tailored for developers.