Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

nginx + gunicorn

  • Loading branch information...
commit f7898a1a5a2f4bb48e51debdf75733f3e47d600b 1 parent d5f1a72
@anandology anandology authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 docs/deploying.rst
View
37 docs/deploying.rst
@@ -58,3 +58,40 @@ Here is a sample lighttpd configuration file to expose a web.py app using fastcg
)
With this configuration lighttpd takes care of starting the application. The webserver talks to your application using fastcgi via a unix domain socket. This means both the webserver and the application will run on the same machine.
+
+nginx + Gunicorn
+----------------
+
+Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project.
+
+To make a web.py application work with gunicorn, you'll need to get the wsgi app from web.py application object. ::
+
+ import web
+ ...
+ app = web.application(urls, globals())
+
+ # get the wsgi app from web.py application object
+ wsgiapp = app.wsgifunc()
+
+Once that change is made, gunicorn server be started using:
+
+ gunicorn -w 4 -b 127.0.0.1:4000 yourapp:wsgiapp
+
+This starts gunicorn with 4 workers and listens at port 4000 on localhost.
+
+It is best to use Gunicorn behind HTTP proxy server. The gunicorn team strongly advises to use nginx.
+Here is a sample nginx configuration which proxies to application running on `127.0.0.1:4000`. ::
+
+ server {
+ listen 80;
+ server_name example.org;
+ access_log /var/log/nginx/example.log;
+
+ location / {
+ proxy_pass http://127.0.0.1:4000;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ }
+ }
Please sign in to comment.
Something went wrong with that request. Please try again.