Changes between Version 8 and Version 9 of Gunicorn
- Timestamp:
- Feb 18, 2015, 5:18:01 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Gunicorn
v8 v9 1 = Running Trac with Gunicorn =1 = Running Trac with Gunicorn 2 2 3 Gunicorn (Green Unicorn) is a Python WSGI HTTP Server for UNIX. It's 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. 4 3 [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. 5 4 6 5 1. Install gunicorn 7 6 8 Gunicorn is a python project which lives on pypi, so we can use easy_install or pip to install gunicorn:7 Gunicorn is a Python project which lives on pypi, so we can use easy_install or pip to install gunicorn: 9 8 10 9 {{{ … … 14 13 I prefer to use a virtualenv (http://pypi.python.org/pypi/virtualenv), to not have to install gunicorn in a system wide fashion. 15 14 16 17 15 2. Write your wsgi file 18 16 19 Gunicorn is WSGI compliant, so we need a simple python script `tracwsgi.py` that work as an entry point: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: 20 18 21 19 {{{ … … 35 33 }}} 36 34 37 Now , we willtest it:35 Now to test it: 38 36 39 37 {{{ … … 47 45 }}} 48 46 49 Now, launch your web browser, and go to http://yourip:8000 and it should work. 50 How it works: gunicorn is looking for a method called "application" in the tracwsgi.py file 51 47 In your web browser go to http://yourIP:8000 and it should work. 48 How it works: gunicorn is looking for a method called "application" in the tracwsgi.py file. 52 49 53 50 3. Configure Nginx 54 51 55 So, now we have Gunicorn running, but we will make it work with nginx which will redirect Trac requests to gunicorn:52 So, now we have Gunicorn running, but we will make it work with Nginx which will redirect Trac requests to gunicorn: 56 53 57 54 {{{ … … 83 80 } 84 81 85 86 82 }}} 87 83 88 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: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: 89 85 http://wiki.nginx.org/HttpUpstreamModule 90 86 91 87 To add a basic or digest authentication, you'll have to provide a file as in the example above, created using htpasswd file. 92 To make gunicorn listen on a unix socket, add this option 88 To make gunicorn listen on a unix socket, add this option: 93 89 94 90 {{{ … … 98 94 }}} 99 95 100 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: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: 101 97 102 98 {{{ … … 118 114 }}} 119 115 120 Another 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.116 '''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. 121 117 122 118 {{{