Edgewall Software

Changes between Version 9 and Version 10 of Gunicorn


Ignore:
Timestamp:
Feb 18, 2015, 10:27:08 PM (9 years ago)
Author:
Ryan J Ollos
Comment:

More cosmetic changes.

Legend:

Unmodified
Added
Removed
Modified
  • Gunicorn

    v9 v10  
    33[http://gunicorn.org/ Gunicorn] (Green Unicorn) is a Python WSGI HTTP Server for UNIX. It is a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resources, and fairly speedy.
    44
    5  1. Install gunicorn
     51. Install gunicorn
    66
    77Gunicorn is a Python project which lives on pypi, so we can use easy_install or pip to install gunicorn:
    8 
    9 {{{
    10     $> pip install gunicorn
     8{{{#!sh
     9$> pip install gunicorn
    1110}}}
    1211
    13 I prefer to use a virtualenv (http://pypi.python.org/pypi/virtualenv), to not have to install gunicorn in a system wide fashion.
     12I prefer to use a [http://pypi.python.org/pypi/virtualenv virtualenv], to not have to install gunicorn in a system wide fashion.
    1413
    15  2. Write your wsgi file
     142. Write your wsgi file
    1615
    17 Gunicorn is [http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface WSGI compliant], so we need a simple Python script `tracwsgi.py` that work as an entry point:
     16Gunicorn is [http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface WSGI compliant], so we need a simple Python script `tracwsgi.py` that functions as an entry point:
    1817
    19 {{{
     18{{{#!python
    2019import sys
    2120import os
     
    3534Now to test it:
    3635
    37 {{{
    38 
     36{{{#!sh
    3937$> gunicorn -w2 tracwsgi:application -b 0.0.0.0:8000
    40382011-03-04 13:21:10 [14900] [INFO] Starting gunicorn 0.12.0
     
    42402011-03-04 13:21:10 [14901] [INFO] Booting worker with pid: 14901
    43412011-03-04 13:21:10 [14902] [INFO] Booting worker with pid: 14902
    44 
    4542}}}
    4643
    47 In your web browser go to http://yourIP:8000 and it should work.
     44In your web browser go to http://localhost:8000 and it should work.
    4845How it works: gunicorn is looking for a method called "application" in the tracwsgi.py file.
    4946
    50  3. Configure Nginx
     473. Configure Nginx
    5148
    5249So, now we have Gunicorn running, but we will make it work with Nginx which will redirect Trac requests to gunicorn:
    5350
    54 {{{
    55 
     51{{{#!nginx
    5652upstream trac_gunicorn {
    5753    server unix:///home/repos/projects/run/trac.sock;
     
    7975    }
    8076}
    81 
    8277}}}
    8378
    84 '''Note''': Nginx will redirect requests to a UNIX socket. It can be a simple ip:port combination. It can be a multiple instance of gunicorn. Take a look in the Nginx documentation:
    85 http://wiki.nginx.org/HttpUpstreamModule
     79'''Note''': Nginx will redirect requests to a UNIX socket. It can be a simple ip:port combination. It can be a multiple instance of gunicorn. Take a look in the [http://wiki.nginx.org/HttpUpstreamModule Nginx documentation].
    8680
    8781To add a basic or digest authentication, you'll have to provide a file as in the example above, created using htpasswd file.
    8882To make gunicorn listen on a unix socket, add this option:
    8983
    90 {{{
    91 
     84{{{#!sh
    9285gunicorn -w2 -b unix:///home/repos/projects/run/trac.sock tracwsgi:application
    93 
    9486}}}
    9587
    96 '''Note''': It seems the WSGI entry point does not handle the Digest or Basic http authentication. To ensure the authentication middleware is passed, you have to hack a little bit the tracwsgi.py:
     88'''Note''': It seems the WSGI entry point does not handle the digest or basic http authentication. To ensure the authentication middleware is passed, you have to hack a little bit the `tracwsgi.py`:
    9789
    98 {{{
    99 
     90{{{#!python
    10091import sys
    10192import os
     
    116107'''Note''': if using digest authentication you must create the authentication handler outside of the application def, otherwise the !DigestAuthentication object won't retain state between requests.
    117108
    118 {{{
     109{{{#!python
    119110import sys
    120111import os