mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
196 lines
7.2 KiB
HTML
196 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Green Unicorn - Deploy</title>
|
|
<link rel="alternate" type="application/rss+xml" href="/feed.xml" />
|
|
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
|
|
</head>
|
|
<body>
|
|
<div id="container" class="twocolumn">
|
|
<div id="menu">
|
|
<div class="logo">
|
|
<a href="./">
|
|
<img src="images/gunicorn.png" alt="Gunicorn - Green Unicorn" />
|
|
</a>
|
|
</div>
|
|
<ul id="actions">
|
|
<li><a href="install.html">Install</a></li>
|
|
<li><a href="run.html">Run</a></li>
|
|
<li><a href="configure.html">Configure</a></li>
|
|
<li><a href="deploy.html">Deploy</a></li>
|
|
<li><a href="design.html">Design</a></li>
|
|
<li><a href="faq.html">FAQ</a></li>
|
|
<li><a href="news.html">News</a></li>
|
|
<li><a href="http://github.com/benoitc/gunicorn/">Code</a></li>
|
|
<li><a href="http://github.com/benoitc/gunicorn/issues">Issues</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="content">
|
|
<div class="document">
|
|
<div class="section" id="nginx-configuration">
|
|
<h2><a class="toc-backref" href="#contents">Nginx Configuration</a></h2>
|
|
<p>Although there are many HTTP proxies available, we strongly advise that you
|
|
use <a class="reference external" href="http://www.nginx.org">Nginx</a>. If you choose another proxy server you need to make sure that it
|
|
buffers slow clients when you use default Gunicorn workers. Without this
|
|
buffering Gunicorn will be easily susceptible to denial-of-service attacks.
|
|
You can use <a class="reference external" href="http://ha.ckers.org/slowloris/">slowloris</a> to check if your proxy is behaving properly.</p>
|
|
<p>An <a class="reference external" href="http://github.com/benoitc/gunicorn/blob/master/examples/nginx.conf">example configuration</a> file for fast clients with <a class="reference external" href="http://www.nginx.org">Nginx</a>:</p>
|
|
<pre class="literal-block">
|
|
worker_processes 1;
|
|
|
|
user nobody nogroup;
|
|
pid /tmp/nginx.pid;
|
|
error_log /tmp/nginx.error.log;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
accept_mutex off;
|
|
}
|
|
|
|
http {
|
|
include mime.types;
|
|
default_type application/octet-stream;
|
|
access_log /tmp/nginx.access.log combined;
|
|
sendfile on;
|
|
|
|
upstream app_server {
|
|
server unix:/tmp/gunicorn.sock fail_timeout=0;
|
|
# For a TCP configuration:
|
|
# server 192.168.0.7:8000 fail_timeout=0;
|
|
}
|
|
|
|
server {
|
|
listen 80 default;
|
|
client_max_body_size 4G;
|
|
server_name _;
|
|
|
|
keepalive_timeout 5;
|
|
|
|
# path for static files
|
|
root /path/to/app/current/public;
|
|
|
|
location / {
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header Host $http_host;
|
|
proxy_redirect off;
|
|
|
|
if (!-f $request_filename) {
|
|
proxy_pass http://app_server;
|
|
break;
|
|
}
|
|
}
|
|
|
|
error_page 500 502 503 504 /500.html;
|
|
location = /500.html {
|
|
root /path/to/app/current/public;
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
<p>If you want to be able to handle streaming request/responses or other fancy
|
|
features like Comet, Long polling, or Web sockets, you need to turn off the
|
|
proxy buffering. <strong>When you do this</strong> you must run with one of the async worker
|
|
classes.</p>
|
|
<p>To turn off buffering, you only need to add <tt class="docutils literal">proxy_buffering off;</tt> to your
|
|
<tt class="docutils literal">location</tt> block:</p>
|
|
<pre class="literal-block">
|
|
...
|
|
location / {
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header Host $http_host;
|
|
proxy_redirect off;
|
|
proxy_buffering off;
|
|
|
|
if (!-f $request_filename) {
|
|
proxy_pass http://app_server;
|
|
break;
|
|
}
|
|
}
|
|
...
|
|
</pre>
|
|
</div>
|
|
<div class="section" id="using-virtualenv">
|
|
<h2><a class="toc-backref" href="#contents">Using Virtualenv</a></h2>
|
|
<p>To serve an app from a <a class="reference external" href="http://pypi.python.org/pypi/virtualenv">Virtualenv</a> it is generally easiest to just install
|
|
Gunicorn directly into the Virtualenv. This will create a set of Gunicorn
|
|
scripts for that Virtualenv which can be used to run applications normally.</p>
|
|
<p>If you have Virtualenv installed, you should be able to do something like
|
|
this:</p>
|
|
<pre class="literal-block">
|
|
$ mkdir ~/venvs/
|
|
$ virtualenv ~/venvs/webapp
|
|
$ source ~/venvs/webapp/bin/activate
|
|
$ ~/venvs/webapp/bin/easy_install -U gunicorn
|
|
$ deactivate
|
|
</pre>
|
|
<p>Then you just need to use one of the three Gunicorn scripts that was installed
|
|
into <tt class="docutils literal">~/venvs/webapp/bin</tt>.</p>
|
|
</div>
|
|
<div class="section" id="monitoring">
|
|
<h2><a class="toc-backref" href="#contents">Monitoring</a></h2>
|
|
<div class="note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">Make sure that when using either of these service monitors you do not
|
|
enable the Gunicorn's daemon mode. These monitors expect that the process
|
|
they launch will be the process they need to monior. Daemonizing
|
|
will fork-exec which creates an unmonitored process and generally just
|
|
confuses the monitor services.</p>
|
|
</div>
|
|
<div class="section" id="runit">
|
|
<h3><a class="toc-backref" href="#contents">Runit</a></h3>
|
|
<p>A popular method for deploying Gunicorn is to have it monitored by <a class="reference external" href="http://smarden.org/runit/">runit</a>.
|
|
An <a class="reference external" href="http://github.com/benoitc/gunicorn/blob/master/examples/gunicorn_rc">example service</a> definition:</p>
|
|
<pre class="literal-block">
|
|
#!/bin sh
|
|
|
|
GUNICORN=/usr/local/bin/gunicorn
|
|
ROOT=/path/to/project
|
|
PID=/var/run/gunicorn.pid
|
|
|
|
APP=main:application
|
|
|
|
if [ -f $PID ]; then rm $PID fi
|
|
|
|
cd $ROOT
|
|
exec $GUNICORN -c $ROOT/gunicorn.conf.py --pidfile=$PID $APP
|
|
</pre>
|
|
</div>
|
|
<div class="section" id="supervisor">
|
|
<h3><a class="toc-backref" href="#contents">Supervisor</a></h3>
|
|
<p>Another useful tool to monitor and control Gunicorn is <a class="reference external" href="http://supervisord.org">Supervisor</a>. A
|
|
<a class="reference external" href="http://github.com/benoitc/gunicorn/blob/master/examples/supervisor.conf">simple configuration</a> is:</p>
|
|
<pre class="literal-block">
|
|
[program:gunicorn]
|
|
command=/path/to/gunicorn main:application -c /path/to/gunicorn.conf.py
|
|
directory=/path/to/project
|
|
user=nobody
|
|
autostart=true
|
|
autorestart=true
|
|
redirect_stderr=True
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="toc">
|
|
<div class="contents topic" id="contents">
|
|
<p class="topic-title first">Contents</p>
|
|
<ul class="simple">
|
|
<li><a class="reference internal" href="#nginx-configuration" id="id3">Nginx Configuration</a></li>
|
|
<li><a class="reference internal" href="#using-virtualenv" id="id4">Using Virtualenv</a></li>
|
|
<li><a class="reference internal" href="#monitoring" id="id5">Monitoring</a><ul>
|
|
<li><a class="reference internal" href="#runit" id="id6">Runit</a></li>
|
|
<li><a class="reference internal" href="#supervisor" id="id7">Supervisor</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div id="footer">
|
|
<p>Site Content License <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.</p>
|
|
<p>Hosted on <a href="http://github.com/">GitHub</a></p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |