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 fileTake 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 back1mod_wsgi2========Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 3why, one step back3Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 4–6why, one step back4`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 back7Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 8–9why, one step back8* Tightly integrated with Apache httpd.9* Supports Windows directly.Merge branch '2.1.x'David Lordbefore adoption97298e0
line 10why, one step back10* Requires a compiler and the Apache development headers to install.Merge branch '2.1.x'David Lordbefore adoption9139af1
line 11why, one step back11* Does not require a reverse proxy setup.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 12why, one step back12Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 13–16why, one step back13This 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.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 17why, one step back17Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 18–20why, one step back18.. _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 back2122Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 23–24why, one step back23Installing24----------Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 25why, one step back25Merge branch '2.1.x'David Lordbefore adoption97298e0
lines 26–28why, one step back26Installing 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.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 29why, one step back29Merge branch '2.1.x'David Lordbefore adoption9139af1
line 30why, one step back30Create a virtualenv, install your application, then installMerge branch '2.1.x'David Lordbefore adoption97298e0
line 31why, one step back31``mod_wsgi``.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 32why, one step back32Merge branch '2.1.x'David Lordbefore adoption9139af1
line 33why, one step back33.. code-block:: textMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 34why, one step back34Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 35–39why, one step back35 $ cd hello-app36 $ python -m venv venv37 $ . venv/bin/activate38 $ pip install . # install your application39 $ pip install mod_wsgiMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 40–41why, one step back4041Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 42–43why, one step back42Running43-------Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 44why, one step back44Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 45–48why, one step back45The 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.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 49why, one step back49Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 50–51why, one step back50.. code-block:: python51 :caption: ``wsgi.py``Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 52why, one step back52Merge branch '2.1.x'David Lordbefore adoption9139af1
line 53why, one step back53 from hello import appMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 54why, one step back54Merge branch '2.1.x'David Lordbefore adoption9139af1
line 55why, one step back55 application = appMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 56why, one step back56Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 57–58why, one step back57.. code-block:: python58 :caption: ``wsgi.py``Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 59why, one step back59Merge branch '2.1.x'David Lordbefore adoption9139af1
line 60why, one step back60 from hello import create_appMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
lines 61–63why, one step back6162 application = create_app()63Merge branch '2.1.x'David Lordbefore adoption9139af1
line 64why, one step back64Now run the ``mod_wsgi-express start-server`` command.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 65why, one step back65Merge branch '2.1.x'David Lordbefore adoption9139af1
line 66why, one step back66.. code-block:: textMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 67why, one step back67Merge branch '2.1.x'David Lordbefore adoption9139af1
line 68why, one step back68 $ mod_wsgi-express start-server wsgi.py --processes 4Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 69why, one step back69Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 70–71why, one step back70The ``--processes`` option specifies the number of worker processes to71run; a starting value could be ``CPU * 2``.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 72why, one step back72Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 73–75why, one step back73Logs 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 back7677Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 78–79why, one step back78Binding Externally79------------------Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 80why, one step back80Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 81–84why, one step back81Unlike 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.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 85why, one step back85Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 86–88why, one step back86For 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.Merge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 89why, one step back89Merge branch '2.1.x'David Lordbefore adoption9139af1
line 90why, one step back90.. code-block:: textMerge remote-tracking branch 'origin/2.0.x'David Lordbefore adoption4240ace
line 91why, one step back91Merge branch '2.1.x'David Lordbefore adoption9139af1
lines 92–94why, one step back92 $ sudo /home/hello/venv/bin/mod_wsgi-express start-server \93 /home/hello/wsgi.py \94 --user hello --group hello --port 80 --processes 4