Skip to content
Myr

mod_wsgi.rst

This file

Path

docs/deploying/mod_wsgi.rst

94 lines · 2.7 KiB

Last changed by

Merge branch '2.1.x'David Lordbefore adoption97298e0

History of this file

Take it

The walk stopped after 200 commits: lines older than 4240ace point at it.

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 1–2why, one step back
1mod_wsgi
2========

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 3why, one step back
3

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 4–6why, one step back
4`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.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 7why, one step back
7

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 8–9why, one step back
8* Tightly integrated with Apache httpd.
9* Supports Windows directly.

Merge branch '2.1.x'David Lordbefore adoption97298e0

line 10why, one step back
10* Requires a compiler and the Apache development headers to install.

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 11why, one step back
11* Does not require a reverse proxy setup.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 12why, one step back
12

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 13–16why, one step back
13This page outlines the basics of running mod_wsgi-express, not the more
14complex installation and configuration with httpd. Be sure to read the15`mod_wsgi-express`_, `mod_wsgi`_, and `Apache httpd`_ documentation to16understand what features are available.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 17why, one step back
17

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 18–20why, one step back
18.. _mod_wsgi-express: https://pypi.org/project/mod-wsgi/
19.. _mod_wsgi: https://modwsgi.readthedocs.io/20.. _Apache httpd: https://httpd.apache.org/

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

lines 21–22why, one step back
21
22

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 23–24why, one step back
23Installing
24----------

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 25why, one step back
25

Merge branch '2.1.x'David Lordbefore adoption97298e0

lines 26–28why, one step back
26Installing mod_wsgi requires a compiler and the Apache server and
27development 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.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 29why, one step back
29

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 30why, one step back
30Create a virtualenv, install your application, then install

Merge branch '2.1.x'David Lordbefore adoption97298e0

line 31why, one step back
31``mod_wsgi``.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 32why, one step back
32

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 33why, one step back
33.. code-block:: text

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 34why, one step back
34

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 35–39why, one step back
35 $ cd hello-app
36 $ python -m venv venv37 $ . venv/bin/activate38 $ pip install . # install your application39 $ pip install mod_wsgi

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

lines 40–41why, one step back
40
41

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 42–43why, one step back
42Running
43-------

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 44why, one step back
44

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 45–48why, one step back
45The only argument to ``mod_wsgi-express`` specifies a script containing
46your 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.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 49why, one step back
49

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 50–51why, one step back
50.. code-block:: python
51 :caption: ``wsgi.py``

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 52why, one step back
52

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 53why, one step back
53 from hello import app

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 54why, one step back
54

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 55why, one step back
55 application = app

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 56why, one step back
56

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 57–58why, one step back
57.. code-block:: python
58 :caption: ``wsgi.py``

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 59why, one step back
59

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 60why, one step back
60 from hello import create_app

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

lines 61–63why, one step back
61
62 application = create_app()63

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 64why, one step back
64Now run the ``mod_wsgi-express start-server`` command.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 65why, one step back
65

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 66why, one step back
66.. code-block:: text

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 67why, one step back
67

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 68why, one step back
68 $ mod_wsgi-express start-server wsgi.py --processes 4

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 69why, one step back
69

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 70–71why, one step back
70The ``--processes`` option specifies the number of worker processes to
71run; a starting value could be ``CPU * 2``.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 72why, one step back
72

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 73–75why, one step back
73Logs 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.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

lines 76–77why, one step back
76
77

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 78–79why, one step back
78Binding Externally
79------------------

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 80why, one step back
80

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 81–84why, one step back
81Unlike the other WSGI servers in these docs, mod_wsgi can be run as
82root 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.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 85why, one step back
85

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 86–88why, one step back
86For example, if you created a ``hello`` user and group, you should
87install your virtualenv and application as that user, then tell88mod_wsgi to drop to that user after starting.

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 89why, one step back
89

Merge branch '2.1.x'David Lordbefore adoption9139af1

line 90why, one step back
90.. code-block:: text

Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace

line 91why, one step back
91

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 92–94why, one step back
92 $ sudo /home/hello/venv/bin/mod_wsgi-express start-server \
93 /home/hello/wsgi.py \94 --user hello --group hello --port 80 --processes 4