Upsun User Documentation

Web servers

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!ยน A monthly $19 perk!
ยนTerms and conditions apply
Activate your 15-day trial

The Python ecosystem offers a number of web servers that can be used to deploy to Upsun. The following examples deploy a Django project named myapp. They assume a myapp/wsgi.py or myapp/asgi.py file with a callable application. Adjust the examples to fit your framework and app.

Gunicorn Anchor to this heading

Gunicorn is a Python WSGI HTTP Server for Unix that operates on a pre-fork worker model. The Gunicorn server is broadly compatible with various web frameworks, light on server resource usage, and fast.

To deploy with Gunicorn on Upsun , use one of the following examples to update your app configuration.

The examples vary based on both your package manager (Pip, Pipenv, or Poetry) and whether your app listens on a TCP (default) or Unix (for running behind a proxy server) socket. For more information on upstream sockets and protocols, see the application reference.

The snippets below assume that Gunicorn has been added as a dependency to your requirements.txt, Pipfile.lock, or poetry.lock.

.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "gunicorn -w 4 -b localhost:$PORT myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "gunicorn -w 4 -b unix:$SOCKET myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "pipenv run gunicorn -w 4 -b localhost:$PORT myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "pipenv run gunicorn -w 4 -b unix:$SOCKET myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "poetry run gunicorn -w 4 -b localhost:$PORT myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "poetry run gunicorn -w 4 -b unix:$SOCKET myapp.wsgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true

Gunicorn workers Anchor to this heading

These examples define four worker processes with -w 4. For more details on what you can configure, see the Gunicorn documentation.

Workers can also be defined with a custom worker class, such as Uvicorn, gevent, or Tornado.

For example, to add a Uvicorn worker class to the pip example for Unix, adjust the start command to the following:

.upsun/config.yaml
applications:
    # The app's name, which must be unique within the project.
    myapp:
        type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b unix:$SOCKET myapp.wsgi:application"

Daphne Anchor to this heading

Daphne is a HTTP, HTTP2 ,and WebSocket protocol server for ASGI and ASGI-HTTP, developed to power Django Channels.

To deploy with Daphne on Upsun , use one of the following examples to update your app configuration.

The examples vary based on both your package manager (Pip, Pipenv, or Poetry) and whether your app listens on a TCP (default) or Unix (for running behind a proxy server) socket. For more information on upstream sockets and protocols, see the application reference.

The snippets below assume that Daphne has been added as a dependency to your requirements.txt, Pipfile.lock, or poetry.lock.

.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "daphne -p $PORT myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "daphne -u $SOCKET myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "pipenv run daphne -p $PORT myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "pipenv run daphne -u $SOCKET myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "poetry run daphne -p $PORT myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "poetry run -u $SOCKET myapp.asgi:application"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true

Uvicorn Anchor to this heading

Uvicorn is an ASGI web server implementation for Python.

To deploy with Uvicorn on Upsun , use one of the following examples to update your app configuration.

The examples vary based on both your package manager (Pip, Pipenv, or Poetry) and whether your app listens on a TCP (default) or Unix (for running behind a proxy server) socket. For more information on upstream sockets and protocols, see the application reference.

The snippets below assume that Uvicorn has been added as a dependency to your requirements.txt, Pipfile.lock, or poetry.lock.

.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "uvicorn myapp.asgi:application --port $PORT --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "uvicorn myapp.asgi:application --uds $SOCKET --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "pipenv run uvicorn myapp.asgi:application --port $PORT --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "pipenv run uvicorn myapp.asgi:application --uds $SOCKET --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "poetry run uvicorn myapp.asgi:application --port $PORT --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "poetry run uvicorn myapp.asgi:application --uds $SOCKET --workers 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true

Uvicorn workers Anchor to this heading

These examples define four worker processes with -w 4. For more recommendations on this and other settings, see the Uvicorn documentation.

Instead of the -w flag, you can also use the WEB_CONCURRENCY variable. See how to set variables.

Hypercorn Anchor to this heading

Hypercorn is an ASGI and WSGI web server inspired by Gunicorn.

To deploy with Hypercorn on Upsun , use one of the following examples to update your app configuration.

The examples vary based on both your package manager (Pip, Pipenv, or Poetry) and whether your app listens on a TCP (default) or Unix (for running behind a proxy server) socket. For more information on upstream sockets and protocols, see the application reference.

The snippets below assume that Hypercorn has been added as a dependency to your requirements.txt, Pipfile.lock, or poetry.lock.

.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "hypercorn myapp.asgi:application -b localhost:$PORT -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "hypercorn myapp.asgi:application -b unix:$SOCKET -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "pipenv run hypercorn myapp.asgi:application -b localhost:$PORT -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "pipenv run hypercorn myapp.asgi:application -b unix:$SOCKET -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            commands:
                start: "poetry run hypercorn myapp.asgi:application -b localhost:$PORT -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true
.upsun/config.yaml
applications:
    # The name of the app container. Must be unique within a project.
    myapp:
        # The location of the application's code.
        source:
            root: "/"
       type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "poetry run hypercorn myapp.asgi:application -b unix:$SOCKET -w 4"
            locations:
                "/":
                    passthru: true
                "/static":
                    root: "static"
                    expires: 1h
                    allow: true

Hypercorn workers Anchor to this heading

These examples define four worker processes with -w 4. For more details on what you can configure, see the Hypercorn documentation.

Workers can also be defined with a custom worker class, such as Asyncio, Uvloop, or Trio.

For example, to add a Asyncio worker class to the pip example for Unix, adjust the start command to the following:

.upsun/config.yaml
applications:
    # The app's name, which must be unique within the project.
    myapp:
        type: 'python:3.9'
        web:
            upstream:
                socket_family: unix
            commands:
                start: "hypercorn myapp.asgi:application -b unix:$SOCKET -w 4 -k asyncio"

Is this page helpful?