paulb@390 | 1 | Configuring Apache
|
paulb@390 | 2 | ==================
|
paulb@376 | 3 |
|
paulb@569 | 4 | To configure applications without authenticators, use the
|
paulb@569 | 5 | webstack_apache_config.py script (installed with setup.py but also found in
|
paulb@569 | 6 | tools/Apache) to set up mod_python applications. For example:
|
paulb@376 | 7 |
|
paulb@569 | 8 | python webstack_apache_config.py \
|
paulb@376 | 9 | mod_python \
|
paulb@376 | 10 | /home/paulb/Software/Python/WebStack/examples/ModPython/CookiesApp/CookiesHandler.py \
|
paulb@376 | 11 | /etc/apache2/sites-available \
|
paulb@376 | 12 | cookies-mod \
|
paulb@376 | 13 | /cookies \
|
paulb@376 | 14 |
|
paulb@390 | 15 | This script can also be used to configure CGI applications. Run the script
|
paulb@390 | 16 | without any arguments to see the documentation.
|
paulb@390 | 17 |
|
paulb@390 | 18 | With the above command, the "cookies" application should be visitable with
|
paulb@390 | 19 | URLs resembling these:
|
paulb@376 | 20 |
|
paulb@538 | 21 | http://localhost/cookies/test
|
paulb@538 | 22 | http://localhost/cookies/my-cookies
|
paulb@376 | 23 |
|
paulb@390 | 24 | The Manual Approach
|
paulb@390 | 25 | -------------------
|
paulb@376 | 26 |
|
paulb@538 | 27 | For each application, add a Location section to httpd.conf (or an appropriate
|
paulb@538 | 28 | equivalent configuration file) as follows:
|
paulb@19 | 29 |
|
paulb@538 | 30 | <Location "/simple">
|
paulb@538 | 31 | SetHandler python-program
|
paulb@20 | 32 | PythonHandler SimpleHandler
|
paulb@19 | 33 | PythonDebug On
|
paulb@538 | 34 | PythonPath "['/home/paulb/Software/Python/WebStack/examples/ModPython/SimpleApp'] + sys.path"
|
paulb@538 | 35 | </Location>
|
paulb@34 | 36 |
|
paulb@111 | 37 | The WebStack package must reside on the PYTHONPATH, along with the package
|
paulb@111 | 38 | containing the application itself. Therefore, ensure that the handler uses the
|
paulb@538 | 39 | appropriate entries in sys.path or use the PythonPath directive as shown
|
paulb@538 | 40 | above.
|
paulb@111 | 41 |
|
paulb@111 | 42 | Using the above definition in httpd.conf, only server resources residing
|
paulb@538 | 43 | directly below "/simple" in the URL "hierarchy" would be associated with the
|
paulb@538 | 44 | Simple WebStack application's resources. Therefore, the following URL paths
|
paulb@538 | 45 | would access the application:
|
paulb@34 | 46 |
|
paulb@538 | 47 | /simple/home
|
paulb@538 | 48 | /simple/tasks/my-tasks
|
paulb@538 | 49 | /simple/agenda/tomorrow/first-thing
|
paulb@51 | 50 |
|
paulb@390 | 51 | Authentication/Authorisation in mod_python
|
paulb@390 | 52 | ==========================================
|
paulb@51 | 53 |
|
paulb@77 | 54 | Apache imposes fairly strict controls over authentication, requiring the
|
paulb@77 | 55 | addition of various declarations in the configuration in order to impose
|
paulb@77 | 56 | access controls on applications, and for WebStack authenticators to be used, a
|
paulb@77 | 57 | "PythonAuthenHandler" must be declared in the application's configuration
|
paulb@77 | 58 | section.
|
paulb@51 | 59 |
|
paulb@51 | 60 | Consequently, it is necessary to define authentication methods in the
|
paulb@51 | 61 | httpd.conf file as in the following example:
|
paulb@51 | 62 |
|
paulb@538 | 63 | <Location "/auth">
|
paulb@538 | 64 | SetHandler python-program
|
paulb@51 | 65 | PythonHandler AuthHandler
|
paulb@77 | 66 | PythonAuthenHandler AuthHandler
|
paulb@51 | 67 | PythonDebug On
|
paulb@51 | 68 | AuthType Basic
|
paulb@51 | 69 | AuthName "AuthResource"
|
paulb@538 | 70 | AuthUserFile /etc/apache2/users
|
paulb@51 | 71 | require valid-user
|
paulb@538 | 72 | PythonPath "['/home/paulb/Software/Python/WebStack/examples/ModPython/AuthApp'] + sys.path"
|
paulb@538 | 73 | </Location>
|
paulb@51 | 74 |
|
paulb@51 | 75 | The details of the application's deployment, including the exact pathname of
|
paulb@51 | 76 | the users file and the appropriate access policy, must obviously be defined
|
paulb@51 | 77 | according to the actual application concerned.
|
paulb@269 | 78 |
|
paulb@390 | 79 | Session Storage with mod_python
|
paulb@390 | 80 | ===============================
|
paulb@269 | 81 |
|
paulb@269 | 82 | The very simple SessionStore class provided in WebStack.Helpers.Session, and
|
paulb@269 | 83 | used by the WebStack.ModPython.Transaction class, requires that a directory be
|
paulb@269 | 84 | created under the Apache server root with the name "WebStack-sessions". Here are
|
paulb@269 | 85 | some example commands for doing this:
|
paulb@269 | 86 |
|
paulb@269 | 87 | cd /usr/local/apache2
|
paulb@269 | 88 | mkdir WebStack-sessions
|
paulb@269 | 89 | chown username.groupname WebStack-sessions
|
paulb@269 | 90 |
|
paulb@269 | 91 | The given "username" and "groupname" correspond to the user and group the Apache
|
paulb@269 | 92 | server assumes when running.
|
paulb@635 | 93 |
|
paulb@635 | 94 | Cookies and Redirects
|
paulb@635 | 95 | =====================
|
paulb@635 | 96 |
|
paulb@635 | 97 | It appears that mod_python does not permit the setting of cookies whilst
|
paulb@635 | 98 | redirecting, at least with tested versions of mod_python. When initialising the
|
paulb@635 | 99 | LoginResource, specify use_redirect=0 in the initialisation arguments.
|