Thursday, August 27, 2020

What is Green Unicorn or gun icon

Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resources, and fairly speedy.


Installation

Here's a quick rundown on how to get started with Gunicorn. For more details read the documentation.


$ pip install gunicorn

  $ cat myapp.py

    def app(environ, start_response):

        data = b"Hello, World!\n"

        start_response("200 OK", [

            ("Content-Type", "text/plain"),

            ("Content-Length", str(len(data)))

        ])

        return iter([data])

  $ gunicorn -w 4 myapp:app

  [2014-09-10 10  :22:28 +0000] [30869] [INFO] Listening at: http://127.0.0.1:8000 (30869)

  [2014-09-10 10:22:28 +0000] [30869] [INFO] Using worker: sync

  [2014-09-10 10:22:28 +0000] [30874] [INFO] Booting worker with pid: 30874

  [2014-09-10 10:22:28 +0000] [30875] [INFO] Booting worker with pid: 30875

  [2014-09-10 10:22:28 +0000] [30876] [INFO] Booting worker with pid: 30876

  [2014-09-10 10:22:28 +0000] [30877] [INFO] Booting worker with pid: 30877


Deployment

Gunicorn is a WSGI HTTP server. It is best to use Gunicorn behind an HTTP proxy server. We strongly advise you to use nginx.

Here's an example to help you get started with using nginx:

server {

    listen 80;

    server_name example.org;

    access_log  /var/log/nginx/example.log;


    location / {

        proxy_pass http://127.0.0.1 :8000;

        proxy_set_header Host $host;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    }

  }


Nginx is set up as reverse proxy server to a Gunicorn server running on localhost port 8000.

Read the full documentation at docs.gunicorn.org



References:

https://gunicorn.org/index.html

No comments:

Post a Comment