Install Gunicorn
Install Gunicorn on your machine:gunicorn to your requirements.txt too, so Square Cloud installs it with your other dependencies:
requirements.txt
Basic usage
To run an application with Gunicorn, you need a WSGI application, such as one built with Flask or Django, and you need to know the module name and the variable name that holds the WSGI application object. For example, if you have a Flask application in a file namedapp.py and the Flask instance is named app, you can run it with Gunicorn using the following command:
python -m gunicornruns Gunicorn as a Python module.--bind 0.0.0.0:80tells Gunicorn to listen on all network interfaces on port 80.app:appspecifies the module name (app) and the variable name (app) that contains the WSGI application object.
wsgi.py module Django creates inside your project package (replace myproject with your project’s name):
Additional options
Gunicorn provides several options to customize its behavior. These are the most common ones; the official Gunicorn settings reference lists them all.Workers
--workers <number>
MEMORY. If your application stops with LACK_OF_RAM, lower the number of workers.
Name
--name <name>-n <name>
Worker class
--worker-class <class>-k <class>
sync, but you can also use gevent, eventlet, tornado or other worker type.
Config file
You can also set Gunicorn options in a Python configuration file. Gunicorn automatically loads a file namedgunicorn.conf.py from the directory where it runs, which is your project root on Square Cloud. For any other file name, pass it with -c <file>.
gunicorn.conf.py
--bind option.
Run it on Square Cloud
Create asquarecloud.app file at the root of your project and put the Gunicorn command in its START field, so Square Cloud starts your application with Gunicorn instead of the default python app.py:
Gunicorn must bind to
0.0.0.0:80: Square Cloud delivers your subdomain’s traffic to port 80 of your application. Square Cloud also sets the PORT environment variable to 80, and Gunicorn reads it: without a --bind option, it listens on 0.0.0.0:$PORT when PORT is set.myproject.wsgi:application in START and your project’s manage.py as MAIN. The Flask and Django tutorials cover the full deploy.
Next steps
Flask
Deploy a Flask application behind Gunicorn.
Django
Deploy a Django project behind Gunicorn.
App won't start
Fix EADDRINUSE, LACK_OF_RAM and other startup failures.
Did you like this article?
- We created this content with great care to offer the best help possible. If this article helped you in any way, support our work! Developers have already rated Square Cloud 4.9/5 across 402 reviews on Google and Trustpilot: leave yours too! It helps us understand what matters most to you.
Google Reviews
Leave your review in Google Reviews.
Trustpilot
Leave your review in Trustpilot.

