Ticket #16057: 16057.patch

File 16057.patch, 12.3 KB (added by Aymeric Augustin, 7 years ago)
  • docs/index.txt

    155155    * **Deployment:**
    156156      :doc:`Overview <howto/deployment/index>` |
    157157      :doc:`Apache/mod_wsgi <howto/deployment/modwsgi>` |
    158       :doc:`Apache/mod_python <howto/deployment/modpython>` |
     158      :doc:`uWSGI <howto/deployment/uwsgi>` |
     159      :doc:`Apache/mod_python (deprecated) <howto/deployment/modpython>` |
    159160      :doc:`FastCGI/SCGI/AJP <howto/deployment/fastcgi>` |
    160161      :doc:`Apache authentication <howto/apache-auth>` |
    161162      :doc:`Handling static files <howto/static-files>` |
  • docs/howto/deployment/index.txt

    1010   :maxdepth: 1
    1212   modwsgi
     13   uwsgi
    1314   fastcgi
    1415   mod_python (deprecated) <modpython>
    1617If you're new to deploying Django and/or Python, we'd recommend you try
    17 :doc:`mod_wsgi </howto/deployment/modwsgi>` first. In most cases it'll be the easiest,
    18 fastest, and most stable deployment choice.
     18:doc:`mod_wsgi </howto/deployment/modwsgi>` first. In most cases it'll be
     19the easiest, fastest, and most stable deployment choice.
    2021.. seealso::
    22     * `Chapter 12 of The Django Book`_ discusses deployment and especially
    23       scaling in more detail.
     23    * `Chapter 12 of the Django Book`_ discusses deployment and especially
     24      scaling in more detail. However, it hasn't been updated since mod_python
     25      was deprecated.
    2527.. _chapter 12 of the django book: http://djangobook.com/en/2.0/chapter12/
  • docs/howto/deployment/uwsgi.txt

     2How to use Django with uWSGI
     5.. highlight:: bash
     7uWSGI_ is a fast, self-healing and developer/sysadmin-friendly application
     8container server coded in pure C.
     10It also provides a fast `caching framework`_ but its documentation is not the
     11purpose of this document.
     13.. _uWSGI: http://projects.unbit.it/uwsgi/
     14.. _caching framework: http://projects.unbit.it/uwsgi/wiki/CachingFramework
     17Prerequisite: uWSGI
     20The wiki describes several `installation procedures`_. Using pip, the python
     21package manager, installing any uWSGI version can be done with one command
     22line. For example::
     24    # install current stable version
     25    pip install uwsgi
     27    # or install LTS (long term support)
     28    pip install http://projects.unbit.it/downloads/uwsgi-lts.tar.gz
     30.. _installation procedures: http://projects0.unbit.it/uwsgi/wiki/Install
     32Prerequisite: general concept
     35uWSGI model
     38uWSGI operates on a client-server model. Your Web server (ie. nginx, Apache)
     39communicates with a django-uwsgi "worker" process to serve dynamic contents.
     40The Web server can communicate with the uWSGI process either:
     42* directly by the uWSGI protocol through a socket created by uWSGI,
     43* or by proxying HTTP requests to the minimalist HTTP server built in uWSGI.
     45In the first case: the Web server can do uWSGI protocol (often with a
     46module). It can then use either a Unix domain socket (a "named pipe" on Win32
     47systems), or it can use a TCP socket. What you choose is a matterr of
     48preference. Usually, a TCP socket is easier because connecting to a port
     49doesn't require special permissions.
     51In the second case, the Web server doesn't need to do uWSGI protocol. It just
     52needs to be able to proxy HTTP requests to the HTTP server built-in uWSGI.
     53The procedure is the same than proxying any HTTP server. Note that the Web
     54server is a "reverse proxy" in this case.
     56Configuring the uWSGI server
     59In any case, when you set up your Web server, you'll just need to point its
     60uwsgi or proxy module to the host/port or socket you specified when starting
     61the uWSGI server.
     63.. admonition:: Choosing the socket
     65    The easiest is to set the socket to a high level (>49152) local port like
     66 If the socket is a file, the system administrator must
     67    ensure that the Web server process has read, write and execute privileges
     68    on that file.
     70uWSGI is highly configurable and thus there are many ways to start the
     71process. For example, uwsgi version provides a hundred switches.
     72This guide demonstrates the most important of them, but does not intent to
     73substitute the official manual and online documentation.
     75uWSGI supports configuration through:
     77* environment variables
     78* command line switches
     79* ldap
     80* ini files
     81* xml files
     82* yaml files
     84Managing the uWSGI server
     87The system administrator controls the worker process pool by sending signals
     88to the master process. For example, the unix kill command sends such signals.
     89uWSGI can write the master process id to a "pidfile". A "pidfile" is a plain
     90text file containing just a process id.
     92Starting the server
     95Starting an uWSGI server is the role of the system administrator, like
     96starting the Web server. It is *not* the role of the Web server to start the
     97uWSGI server. This means:
     99* the uWSGI server can be restarted or reloaded independently from the Web
     100  server,
     101* (except with Cheerokee), it is the role of the system administrator to make
     102  uWSGI to start on boot or reboot: either through tools like supervisor or
     103  daemontools, either directly at init level in a file like /etc/rc.local or
     104  /etc/conf.d/local
     106Managing uWSGI
     109Starting the server
     112Example command line for a Web server that understand the uWSGI protocol::
     114    uwsgi --chdir=/path/to/your/project
     115        --module='django.core.handlers.wsgi:WSGIHandler()' \
     116        --env DJANGO_SETTINGS_MODULE=settings \
     117        --master --pidfile=/tmp/project-master.pid \
     118        --socket= \      # can also be a file
     119        --processes=5 \                 # number of worker processes
     120        --uid=1000 --gid=2000 \         # if root, uwsgi can drop privileges
     121        --harakiri=20 \                 # respawn processes taking more than 20 seconds
     122        --limit-as=128 \                # limit the project to 128 Megabytes
     123        --max-requests=5000 \           # respawn processes after serving 5000 requests
     124        --vacuum \                      # clear environment on exit
     125        --home=/path/to/virtual/env \   # optionnal path to a virtualenv
     126        --daemonize=/var/log/uwsgi/yourproject.log      # background the process
     128Django specific options are:
     130* ``chdir``: should be the path to your project
     131* ``module``: uwsgi module to use
     132* ``pythonpath``: optional path to your project virtualenv
     133* ``env``: should contain at least ``DJANGO_SETTINGS_MODULE``
     135Example ini configuration file::
     137    [uwsgi]
     138    chdir=/path/to/your/project
     139    master=True
     140    pidfile=/tmp/project-master.pid
     141    vacuum=True
     142    max-requests=5000
     143    deamonize=/var/log/uwsgi/yourproject.log
     145Example ini configuration file usage::
     147    uwsgi --ini uwsgi.ini
     149Read more `uWSGI configuration examples
     152.. admonition:: Massive application hosting
     154    `uWSGI emperor <http://projects.unbit.it/uwsgi/wiki/Emperor>`_ is a special
     155    uWSGI process that can manage many master processes at once.
     157Reloading the daemon
     160As mentioned above, the uWSGI master process is one of the core component of
     161the uWSGI stack. The signal to brutally reload all the workers and the master
     162process is SIGTERM. Example command to brutally reload the uWSGI processes::
     164    kill -TERM `cat /tmp/project-master.pid`
     166Patching the daemon
     169One of the great advantages of uWSGI is its ability to gradually restart each
     170worker without loosing any request.
     172For example, uWSGI can be signaled that worker should reload the code after
     173handling their current request (if any) from bash::
     175    # using kill to send the signal
     176    kill -HUP `cat /tmp/project-master.pid`
     178    # if uwsgi was started with --touch-reload=/tmp/somefile
     179    touch /tmp/somefile
     181Or from Python::
     183    uwsgi.reload()
     185Stopping the daemon
     188If you have the process running in the foreground, it's easy enough to stop it:
     189Simply hitting ``Ctrl-C`` will stop and quit the uWSGI server. However, when
     190you're dealing with background processes, you'll need to resort to the Unix
     191``kill`` command.
     193The ``kill`` is used to send a signal to the uWSGI master process. The
     194`uWSGI signals are documented online
     195<http://projects.unbit.it/uwsgi/wiki/uWSGISignals>`_. Example command to
     196completely stop the uWSGI stack::
     198    kill -INT `cat /tmp/project-master.pid`
     200HTTP server configuration
     203Nginx setup
     206Nginx provides the `uwsgi module <http://wiki.nginx.org/HttpUwsgiModule>`_ by
     207default since nginx 0.8.40. Configuring Nginx to use an uWSGI server is as
     208simple as setting it up to proxy requests::
     210    location / {
     211        uwsgi_pass;
     212        # in case of a socket file:
     213        # uwsgi_pass unix:/tmp/yourproject.sock;
     214    }
     216Note that default uwsgi parameters should be included somewhere in your Nginx
     217configuration. For example::
     219    http {
     220        include       uwsgi_params;
     221        # [...] normal nginx configuration here
     222    }
     224Cherokee setup
     227Cherokee setup is documented in the `official Cherokee uWSGI documentation
     230Lighttpd setup
     233`Lighttpd uwsgi module <http://projects.unbit.it/uwsgi/wiki/RunOnLighttpd>`_ is
     234still experimental.
     239As usual, the first things to do is to check the logs. This implies:
     241* the web server log, which will indicate if it couldn't connect to the uWSGI
     242  process,
     243* the uWSGI log, which will indicate if an exception was thrown.
     245Typical gotchas:
     247* If the socket is a file, the Web server process should have read, write and
     248  execute permissions on the socket file. The ``--chmod-socket`` option can do
     249  it.
     250* In some cases, for instance if uWSGI was started without ``--vacuum`` or
     251  killed with ``SIGKILL``, it won't remove the socket and pidfile when it is
     252  interrupted. It is safe to remove them manually and to start uWSGI again in
     253  that case.
     254* uWSGI can start the process on the foreground, this will make errors easily
     255  visible to the system administrator.
  • docs/topics/install.txt

    3030If you just want to experiment with Django, skip ahead to the next
    31 section; Django includes a lightweight Web server you can use for
     31section; Django includes a lightweight web server you can use for
    3232testing, so you won't need to set up Apache until you're ready to
    3333deploy Django in production.
    35 If you want to use Django on a production site, use Apache with
     35If you want to use Django on a production site, use `Apache`_ with
    3636`mod_wsgi`_. mod_wsgi can operate in one of two modes: an embedded
    3737mode and a daemon mode. In embedded mode, mod_wsgi is similar to
    3838mod_perl -- it embeds Python within Apache and loads Python code into
    5555If you can't use mod_wsgi for some reason, fear not: Django supports
    56 many other deployment options. Another option is :doc:`FastCGI
     56many other deployment options. One is :doc:`uWSGI </howto/deployment/fastcgi>`;
     57it works very well with `nginx`_. Another is :doc:`FastCGI
    5758</howto/deployment/fastcgi>`, perfect for using Django with servers
    5859other than Apache. Additionally, Django follows the WSGI_ spec, which
    5960allows it to run on a variety of server platforms. See the
    6162instructions for each platform.
    6364.. _Apache: http://httpd.apache.org/
     65.. _nginx: http://nginx.net/
    6466.. _mod_wsgi: http://code.google.com/p/modwsgi/
    6567.. _WSGI: http://www.python.org/dev/peps/pep-0333/
    6668.. _server-arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements
Back to Top