Edgewall Software

Changes between Version 85 and Version 86 of TracModWSGI


Ignore:
Timestamp:
Oct 15, 2019, 6:36:10 AM (2 months ago)
Author:
trac
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracModWSGI

    v85 v86  
    77== The `trac.wsgi` script
    88
    9 Trac can be run on top of mod_wsgi with the help of an application script, which is a Python file saved with a `.wsgi` extension. 
     9Trac can be run on top of mod_wsgi with the help of an application script, which is a Python file saved with a `.wsgi` extension.
    1010
    1111A robust and generic version of this file can be created using the `trac-admin <env> deploy <dir>` command which automatically substitutes the required paths, see TracInstall#cgi-bin. The script should be sufficient for most installations and users not wanting more information can proceed to [#Mappingrequeststothescript configuring Apache].
     
    1515def application(environ, start_request):
    1616    # Add this when you have multiple projects
    17     environ.setdefault('trac.env_parent_dir', '/usr/share/trac/projects') 
     17    environ.setdefault('trac.env_parent_dir', '/usr/share/trac/projects')
    1818    ..
    1919}}}
     
    4949=== A more elaborate script
    5050
    51 If you are using multiple `.wsgi` files (for example one per Trac environment) you must ''not'' use `os.environ['TRAC_ENV']` to set the path to the Trac environment. Using this method may lead to Trac delivering the content of another Trac environment, as the variable may be filled with the path of a previously viewed Trac environment. 
     51If you are using multiple `.wsgi` files (for example one per Trac environment) you must ''not'' use `os.environ['TRAC_ENV']` to set the path to the Trac environment. Using this method may lead to Trac delivering the content of another Trac environment, as the variable may be filled with the path of a previously viewed Trac environment.
    5252
    5353To solve this problem, use the following `.wsgi` file instead:
     
    5959import trac.web.main
    6060def application(environ, start_response):
    61   environ['trac.env_path'] = '/usr/local/trac/mysite' 
     61  environ['trac.env_path'] = '/usr/local/trac/mysite'
    6262  return trac.web.main.dispatch_request(environ, start_response)
    6363}}}
    6464
    65 For clarity, you should give this file a `.wsgi` extension. You should probably put the file in its own directory, since you will expose it to Apache. 
     65For clarity, you should give this file a `.wsgi` extension. You should probably put the file in its own directory, since you will expose it to Apache.
    6666
    6767If you have installed Trac and Python eggs in a path different from the standard one, you should add that path by adding the following code at the top of the wsgi script:
     
    208208See also the [https://httpd.apache.org/docs/2.4/mod/mod_auth_basic.html mod_auth_digest] documentation.
    209209
    210 === Using LDAP Authentication 
     210=== Using LDAP Authentication
    211211
    212212Configuration for [https://httpd.apache.org/docs/2.4/mod/mod_ldap.html mod_ldap] authentication in Apache is more involved (httpd 2.2+ and OpenLDAP: slapd 2.3.19).
     
    268268
    269269See also:
    270  - [https://httpd.apache.org/docs/2.4/mod/mod_authnz_ldap.html mod_authnz_ldap], documentation for mod_authnz_ldap.   
     270 - [https://httpd.apache.org/docs/2.4/mod/mod_authnz_ldap.html mod_authnz_ldap], documentation for mod_authnz_ldap.
    271271 - [https://httpd.apache.org/docs/2.4/mod/mod_ldap.html mod_ldap], documentation for mod_ldap, which provides connection pooling and a shared cache.
    272272 - [https://trac-hacks.org/wiki/LdapPlugin TracHacks:LdapPlugin] for storing TracPermissions in LDAP.
     
    310310
    311311{{{#!python
    312 def application(environ, start_request): 
    313     # Set authenticated username on CA SiteMinder to REMOTE_USER variable 
     312def application(environ, start_request):
     313    # Set authenticated username on CA SiteMinder to REMOTE_USER variable
    314314    # strip() is used to remove any spaces on the end of the string
    315     if 'HTTP_SM_USER' in environ: 
     315    if 'HTTP_SM_USER' in environ:
    316316        environ['REMOTE_USER'] = environ['HTTP_REMOTE_USER'].strip()
    317317    ...
     
    415415//This is not a recommended approach though. See also the notes at the bottom of the [https://code.google.com/archive/p/modwsgi/wikis/IntegrationWithTrac.wiki mod_wsgi's IntegrationWithTrac] wiki page.//
    416416
    417 === Missing Headers and Footers
    418 
    419 If python optimizations are enabled, then headers and footers will not be rendered. An error will be raised in Trac 1.0.11 and later when optimizations are enabled.
    420 
    421 In your WSGI configuration file, the `WSGIPythonOptimize` setting must be set to `0` (`1` or `2` will not work):
    422 
    423 {{{#!apache
    424     WSGIPythonOptimize 0
    425 }}}
    426 
    427 On Ubuntu, the WSGI mod configuration is at `/etc/apache2/mods-enabled/wsgi.conf`.
    428 
    429 The same issue is seen with `PythonOptimize On` in [TracModPython#Pagelayoutissues ModPython].
    430 
    431417=== Other resources
    432418