Skip to content
Myr

mod_wsgi.rst

This file

Path

docs/deploying/mod_wsgi.rst

94 lines · 2.7 KiB

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 73739a2 point at it.

Merge branch '2.2.x'David Lordbefore adoption73739a2

lines 1–94why, one step back
1mod_wsgi
2========34`mod_wsgi`_ is a WSGI server integrated with the `Apache httpd`_ server.5The modern `mod_wsgi-express`_ command makes it easy to configure and6start the server without needing to write Apache httpd configuration.78* Tightly integrated with Apache httpd.9* Supports Windows directly.10* Requires a compiler and the Apache development headers to install.11* Does not require a reverse proxy setup.1213This page outlines the basics of running mod_wsgi-express, not the more14complex installation and configuration with httpd. Be sure to read the15`mod_wsgi-express`_, `mod_wsgi`_, and `Apache httpd`_ documentation to16understand what features are available.1718.. _mod_wsgi-express: https://pypi.org/project/mod-wsgi/19.. _mod_wsgi: https://modwsgi.readthedocs.io/20.. _Apache httpd: https://httpd.apache.org/212223Installing24----------2526Installing mod_wsgi requires a compiler and the Apache server and27development headers installed. You will get an error if they are not.28How to install them depends on the OS and package manager that you use.2930Create a virtualenv, install your application, then install31``mod_wsgi``.3233.. code-block:: text3435 $ cd hello-app36 $ python -m venv .venv37 $ . .venv/bin/activate38 $ pip install . # install your application39 $ pip install mod_wsgi404142Running43-------4445The only argument to ``mod_wsgi-express`` specifies a script containing46your Flask application, which must be called ``application``. You can47write a small script to import your app with this name, or to create it48if using the app factory pattern.4950.. code-block:: python51 :caption: ``wsgi.py``5253 from hello import app5455 application = app5657.. code-block:: python58 :caption: ``wsgi.py``5960 from hello import create_app6162 application = create_app()6364Now run the ``mod_wsgi-express start-server`` command.6566.. code-block:: text6768 $ mod_wsgi-express start-server wsgi.py --processes 46970The ``--processes`` option specifies the number of worker processes to71run; a starting value could be ``CPU * 2``.7273Logs for each request aren't show in the terminal. If an error occurs,74its information is written to the error log file shown when starting the75server.767778Binding Externally79------------------8081Unlike the other WSGI servers in these docs, mod_wsgi can be run as82root to bind to privileged ports like 80 and 443. However, it must be83configured to drop permissions to a different user and group for the84worker processes.8586For example, if you created a ``hello`` user and group, you should87install your virtualenv and application as that user, then tell88mod_wsgi to drop to that user after starting.8990.. code-block:: text9192 $ sudo /home/hello/.venv/bin/mod_wsgi-express start-server \93 /home/hello/wsgi.py \94 --user hello --group hello --port 80 --processes 4