Changes between Version 1 and Version 2 of TracModWSGI
- Timestamp:
- 08/21/13 19:46:14 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracModWSGI
v1 v2 ˆà 1 1 = Trac and mod_wsgi =ˆà 2 2 ˆà 3 ˆà '''Important note:''' ''Please use either version 1.6, 2.4 or later of `mod_wsgi`. Versions prior to 2.4 in the 2.X branch have problems with some Apache configurations that use WSGI file wrapper extension. This extension is used in Trac to serve up attachments and static media files such as style sheets. If you are affected by this problem attachments will appear to be empty and formatting of HTML pages will appear not to work due to style sheet files not loading properly. See mod_wsgi tickets [http://code.google.com/p/modwsgi/issues/detail?id=100 #100] and [http://code.google.com/p/modwsgi/issues/detail?id=132 #132].''ˆà 4 ˆà ˆà 5 ˆà [http://code.google.com/p/modwsgi/ mod_wsgi] is an Apache module for running WSGI-compatible Python applications directly on top of Apache. The mod_wsgi adapter is written completely in C and provides significantly better performance than using existing WSGI adapters for mod_python or CGI.ˆà 6 ˆà ˆà 7 ˆà Trac can be run on top of mod_wsgi with the help of the following application script, which is just a Python file, though usually saved with a .wsgi extension). This file can be created using '''trac-admin <env> deploy <dir>''' command which automatically substitutes required paths.ˆà 8 ˆà ˆà 9 ˆà {{{ˆà 10 ˆà #!pythonˆà ˆà 3 ˆà ˆà 4 [http://code.google.com/p/modwsgi/ mod_wsgi] is an Apache module for running WSGI-compatible Python applications directly on top of the Apache webserver. The mod_wsgi adapter is written completely in C and provides very good performances.ˆà ˆà 5 ˆà ˆà 6 [[PageOutline(2-3,Overview,inline)]]ˆà ˆà 7 ˆà ˆà 8 == The `trac.wsgi` scriptˆà ˆà 9 ˆà ˆà 10 Trac can be run on top of mod_wsgi with the help of the following application script, which is just a Python file, though usually saved with a `.wsgi` extension). ˆà ˆà 11 ˆà ˆà 12 === A very basic scriptˆà ˆà 13 In its simplest form, the script could be:ˆà ˆà 14 ˆà ˆà 15 {{{#!pythonˆà 11 16 import osˆà 12 17 ˆà òÀæ òÀæ ˆà 20 25 The `TRAC_ENV` variable should naturally be the directory for your Trac environment (if you have several Trac environments in a directory, you can also use `TRAC_ENV_PARENT_DIR` instead), while the `PYTHON_EGG_CACHE` should be a directory where Python can temporarily extract Python eggs.ˆà 21 26 ˆà 22 ˆà '''Important note:''' If you're 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. (The variable may be filled with the path of a previously viewed Trac environment.) To solve this problem, use the following `.wsgi` file instead:ˆà 23 ˆà ˆà 24 ˆà {{{ˆà 25 ˆà #!pythonˆà ˆà 27 === A more elaborate scriptˆà ˆà 28 ˆà ˆà 29 If you're 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. ˆà ˆà 30 ˆà ˆà 31 To solve this problem, use the following `.wsgi` file instead:ˆà ˆà 32 {{{#!pythonˆà 26 33 import osˆà 27 34 ˆà òÀæ òÀæ ˆà 34 41 }}}ˆà 35 42 ˆà 36 ˆà For clarity, you should give this file a `.wsgi` extension. You should probably put the file in it's own directory, since you will open up its directory to Apache. You can create a .wsgi files which handles all this for you by running the TracAdmin command `deploy`.ˆà 37 ˆà ˆà 38 ˆà If you have installed trac and eggs in a path different from the standard one you should add that path by adding the following code on top of the wsgi script:ˆà 39 ˆà ˆà 40 ˆà {{{ˆà 41 ˆà #!pythonˆà ˆà 43 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. ˆà ˆà 44 ˆà ˆà 45 If you have installed Trac and 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:ˆà ˆà 46 ˆà ˆà 47 {{{#!pythonˆà 42 48 import siteˆà 43 49 site.addsitedir('/usr/local/trac/lib/python2.4/site-packages')ˆà 44 50 }}}ˆà 45 51 ˆà 46 ˆà Change it according to the path you installed the trac libs at.ˆà 47 ˆà ˆà 48 ˆà After you've done preparing your wsgi-script, add the following to your httpd.conf.ˆà ˆà 52 Change it according to the path you installed the Trac libs at.ˆà ˆà 53 ˆà ˆà 54 === Recommended `trac.wsgi` scriptˆà ˆà 55 ˆà ˆà 56 A somewhat 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).ˆà ˆà 57 ˆà ˆà 58 ˆà ˆà 59 == Mapping requests to the scriptˆà ˆà 60 ˆà ˆà 61 After you've done preparing your .wsgi script, add the following to your Apache configuration file (`httpd.conf` for example).ˆà 49 62 ˆà 50 63 {{{ˆà òÀæ òÀæ ˆà 58 71 }}}ˆà 59 72 ˆà 60 ˆà Here, the script is in a subdirectory of the Trac environment. In order to let Apache run the script, access to the directory in which the script resides is opened up to all of Apache. Additionally, the {{{WSGIApplicationGroup}}} directive ensures that Trac is always run in the first Python interpreter created by mod_wsgi; this is necessary because the Subversion Python bindings, which are used by Trac, don't always work in other subinterpreters and may cause requests to hang or cause Apache to crash as a result. After adding this configuration, restart Apache, and then it should work.ˆà 61 ˆà ˆà 62 ˆà To test the setup of Apache, mod_wsgi and Python itself (ie. without involving Trac and dependencies), this simple wsgi application can be used to make sure that requests gets served (use as only content in your .wsgi script):ˆà 63 ˆà ˆà 64 ˆà {{{ˆà ˆà 73 Here, the script is in a subdirectory of the Trac environment.ˆà ˆà 74 ˆà ˆà 75 If you followed the directions [http://trac.edgewall.org/wiki/TracInstall#cgi-bin Generating the Trac cgi-bin directory], your Apache configuration file should look like following:ˆà ˆà 76 ˆà ˆà 77 {{{ˆà ˆà 78 WSGIScriptAlias /trac /usr/share/trac/cgi-bin/trac.wsgiˆà ˆà 79 ˆà ˆà 80 <Directory /usr/share/trac/cgi-bin>ˆà ˆà 81 WSGIApplicationGroup %{GLOBAL}ˆà ˆà 82 Order deny,allowˆà ˆà 83 Allow from allˆà ˆà 84 </Directory>ˆà ˆà 85 }}}ˆà ˆà 86 ˆà ˆà 87 In order to let Apache run the script, access to the directory in which the script resides is opened up to all of Apache. Additionally, the `WSGIApplicationGroup` directive ensures that Trac is always run in the first Python interpreter created by mod_wsgi; this is necessary because the Subversion Python bindings, which are used by Trac, don't always work in other sub-interpreters and may cause requests to hang or cause Apache to crash as a result. After adding this configuration, restart Apache, and then it should work.ˆà ˆà 88 ˆà ˆà 89 To test the setup of Apache, mod_wsgi and Python itself (ie. without involving Trac and dependencies), this simple wsgi application can be used to make sure that requests gets served (use as only content in your `.wsgi` script):ˆà ˆà 90 ˆà ˆà 91 {{{#!pythonˆà 65 92 def application(environ, start_response):ˆà 66 93 start_response('200 OK',[('Content-type','text/html')])ˆà òÀæ òÀæ ˆà 68 95 }}}ˆà 69 96 ˆà 70 ˆà See also the mod_wsgi [http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac installation instructions] for Trac.ˆà 71 ˆà ˆà 72 ˆà For troubleshooting tips, see the [TracModPython#Troubleshooting mod_python troubleshooting] section, as most Apache-related issues are quite similar, plus discussion of potential [http://code.google.com/p/modwsgi/wiki/ApplicationIssues application issues] when using mod_wsgi.ˆà ˆà 97 For more information about using the mod_wsgi specific directives, see the [http://code.google.com/p/modwsgi/wiki/ mod_wsgi's wiki] and more specifically the [http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac IntegrationWithTrac] page.ˆà ˆà 98 ˆà ˆà 99 ˆà ˆà 100 == Configuring Authenticationˆà ˆà 101 ˆà ˆà 102 We describe in the the following sections different methods for setting up authentication.ˆà ˆà 103 ˆà ˆà 104 See also [http://httpd.apache.org/docs/2.2/howto/auth.html Authentication, Authorization and Access Control] in the Apache guide.ˆà ˆà 105 ˆà ˆà 106 === Using Basic Authentication ===ˆà ˆà 107 ˆà ˆà 108 The simplest way to enable authentication with Apache is to create a password file. Use the `htpasswd` program to create the password file:ˆà ˆà 109 {{{ˆà ˆà 110 $ htpasswd -c /somewhere/trac.htpasswd adminˆà ˆà 111 New password: <type password>ˆà ˆà 112 Re-type new password: <type password again>ˆà ˆà 113 Adding password for user adminˆà ˆà 114 }}}ˆà ˆà 115 ˆà ˆà 116 After the first user, you dont need the "-c" option anymore:ˆà ˆà 117 {{{ˆà ˆà 118 $ htpasswd /somewhere/trac.htpasswd johnˆà ˆà 119 New password: <type password>ˆà ˆà 120 Re-type new password: <type password again>ˆà ˆà 121 Adding password for user johnˆà ˆà 122 }}}ˆà ˆà 123 ˆà ˆà 124 ''See the man page for `htpasswd` for full documentation.''ˆà ˆà 125 ˆà ˆà 126 After you've created the users, you can set their permissions using TracPermissions.ˆà ˆà 127 ˆà ˆà 128 Now, you'll need to enable authentication against the password file in the Apache configuration:ˆà ˆà 129 {{{ˆà ˆà 130 <Location "/trac/login">ˆà ˆà 131 AuthType Basicˆà ˆà 132 AuthName "Trac"ˆà ˆà 133 AuthUserFile /somewhere/trac.htpasswdˆà ˆà 134 Require valid-userˆà ˆà 135 </Location>ˆà ˆà 136 }}}ˆà ˆà 137 ˆà ˆà 138 If you're hosting multiple projects you can use the same password file for all of them:ˆà ˆà 139 {{{ˆà ˆà 140 <LocationMatch "/trac/[^/]+/login">ˆà ˆà 141 AuthType Basicˆà ˆà 142 AuthName "Trac"ˆà ˆà 143 AuthUserFile /somewhere/trac.htpasswdˆà ˆà 144 Require valid-userˆà ˆà 145 </LocationMatch>ˆà ˆà 146 }}}ˆà ˆà 147 Note that neither a file nor a directory named 'login' needs to exist.[[BR]]ˆà ˆà 148 See also the [http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html mod_auth_basic] documentation.ˆà ˆà 149 ˆà ˆà 150 === Using Digest Authentication ===ˆà ˆà 151 ˆà ˆà 152 For better security, it is recommended that you either enable SSL or at least use the òÀÜdigestòÀÝ authentication scheme instead of òÀÜBasicòÀÝ. ˆà ˆà 153 ˆà ˆà 154 You'll have to create your `.htpasswd` file with the `htdigest` command instead of `htpasswd`, as follows:ˆà ˆà 155 {{{ˆà ˆà 156 # htdigest -c /somewhere/trac.htpasswd trac adminˆà ˆà 157 }}}ˆà ˆà 158 ˆà ˆà 159 The "trac" parameter above is the "realm", and will have to be reused in the Apache configuration in the !AuthName directive:ˆà ˆà 160 ˆà ˆà 161 {{{ˆà ˆà 162 <Location "/trac/login">ˆà ˆà 163 ˆà ˆà 164 AuthType Digestˆà ˆà 165 AuthName "trac"ˆà ˆà 166 AuthDigestDomain /tracˆà ˆà 167 AuthUserFile /somewhere/trac.htpasswdˆà ˆà 168 Require valid-userˆà ˆà 169 </Location>ˆà ˆà 170 }}}ˆà ˆà 171 ˆà ˆà 172 For multiple environments, you can use the same `LocationMatch` as described with the previous method.ˆà ˆà 173 ˆà ˆà 174 Don't forget to activate the mod_auth_digest. For example, on a Debian 4.0r1 (etch) system:ˆà ˆà 175 {{{ˆà ˆà 176 LoadModule auth_digest_module /usr/lib/apache2/modules/mod_auth_digest.soˆà ˆà 177 }}}ˆà ˆà 178 ˆà ˆà 179 ˆà ˆà 180 See also the [http://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html mod_auth_digest] documentation.ˆà ˆà 181 ˆà ˆà 182 === Using LDAP Authentication ˆà ˆà 183 ˆà ˆà 184 Configuration for [http://httpd.apache.org/docs/2.2/mod/mod_ldap.html mod_ldap] authentication in Apache is a bit tricky (httpd 2.2.x and OpenLDAP: slapd 2.3.19)ˆà ˆà 185 ˆà ˆà 186 1. You need to load the following modules in Apache httpd.confˆà ˆà 187 {{{ˆà ˆà 188 LoadModule ldap_module modules/mod_ldap.soˆà ˆà 189 LoadModule authnz_ldap_module modules/mod_authnz_ldap.soˆà ˆà 190 }}}ˆà ˆà 191 ˆà ˆà 192 2. Your httpd.conf also needs to look something like:ˆà ˆà 193 ˆà ˆà 194 {{{ˆà ˆà 195 <Location /trac/>ˆà ˆà 196 # (if you're using it, mod_python specific settings go here)ˆà ˆà 197 Order deny,allowˆà ˆà 198 Deny from allˆà ˆà 199 Allow from 192.168.11.0/24ˆà ˆà 200 AuthType Basicˆà ˆà 201 AuthName "Trac"ˆà ˆà 202 AuthBasicProvider "ldap"ˆà ˆà 203 AuthLDAPURL "ldap://127.0.0.1/dc=example,dc=co,dc=ke?uid?sub?(objectClass=inetOrgPerson)"ˆà ˆà 204 authzldapauthoritative Offˆà ˆà 205 Require valid-userˆà ˆà 206 </Location>ˆà ˆà 207 }}}ˆà ˆà 208 ˆà ˆà 209 ˆà ˆà 210 3. You can use the LDAP interface as a way to authenticate to a Microsoft Active Directory:ˆà ˆà 211 ˆà ˆà 212 ˆà ˆà 213 Use the following as your LDAP URL:ˆà ˆà 214 {{{ˆà ˆà 215 AuthLDAPURL "ldap://directory.example.com:3268/DC=example,DC=com?sAMAccountName?sub?(objectClass=user)"ˆà ˆà 216 }}}ˆà ˆà 217 ˆà ˆà 218 You will also need to provide an account for Apache to use when checkingˆà ˆà 219 credentials. As this password will be listed in plaintext in theˆà ˆà 220 config, you should be sure to use an account specifically for this task:ˆà ˆà 221 {{{ˆà ˆà 222 AuthLDAPBindDN ldap-auth-user@example.comˆà ˆà 223 AuthLDAPBindPassword "password"ˆà ˆà 224 }}}ˆà ˆà 225 ˆà ˆà 226 The whole section looks like:ˆà ˆà 227 {{{ˆà ˆà 228 <Location /trac/>ˆà ˆà 229 # (if you're using it, mod_python specific settings go here)ˆà ˆà 230 Order deny,allowˆà ˆà 231 Deny from allˆà ˆà 232 Allow from 192.168.11.0/24ˆà ˆà 233 AuthType Basicˆà ˆà 234 AuthName "Trac"ˆà ˆà 235 AuthBasicProvider "ldap"ˆà ˆà 236 AuthLDAPURL "ldap://adserver.company.com:3268/DC=company,DC=com?sAMAccountName?sub?(objectClass=user)"ˆà ˆà 237 AuthLDAPBindDN ldap-auth-user@company.comˆà ˆà 238 AuthLDAPBindPassword "the_password"ˆà ˆà 239 authzldapauthoritative Offˆà ˆà 240 # require valid-userˆà ˆà 241 require ldap-group CN=Trac Users,CN=Users,DC=company,DC=comˆà ˆà 242 </Location>ˆà ˆà 243 }}}ˆà ˆà 244 ˆà ˆà 245 Note 1: This is the case where the LDAP search will get around the multiple OUs, conecting to Global Catalog Server portion of AD (Notice the port is 3268, not the normal LDAP 389). The GCS is basically a "flattened" tree which allows searching for a user without knowing to which OU they belong.ˆà ˆà 246 ˆà ˆà 247 Note 2: You can also require the user be a member of a certain LDAP group, instead ofˆà ˆà 248 just having a valid login:ˆà ˆà 249 {{{ˆà ˆà 250 Require ldap-group CN=Trac Users,CN=Users,DC=example,DC=comˆà ˆà 251 }}}ˆà ˆà 252 ˆà ˆà 253 See also:ˆà ˆà 254 - [http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html mod_authnz_ldap], documentation for mod_authnz_ldapˆà ˆà 255 ˆà ˆà 256 - [http://httpd.apache.org/docs/2.2/mod/mod_ldap.html mod_ldap], documentation for mod_ldap, which provides connection pooling and a shared cache.ˆà ˆà 257 - [http://trac-hacks.org/wiki/LdapPlugin TracHacks:LdapPlugin] for storing TracPermissions in LDAP.ˆà ˆà 258 ˆà ˆà 259 === Using SSPI Authenticationˆà ˆà 260 ˆà ˆà 261 If you are using Apache on Windows, you can use mod_auth_sspi to provideˆà ˆà 262 single-sign-on. Download the module from the !SourceForge [http://sourceforge.net/projects/mod-auth-sspi/ mod-auth-sspi project] and then add theˆà ˆà 263 following to your !VirtualHost:ˆà ˆà 264 {{{ˆà ˆà 265 <Location /trac/login>ˆà ˆà 266 AuthType SSPIˆà ˆà 267 AuthName "Trac Login"ˆà ˆà 268 SSPIAuth Onˆà ˆà 269 SSPIAuthoritative Onˆà ˆà 270 SSPIDomain MyLocalDomainˆà ˆà 271 SSPIOfferBasic Onˆà ˆà 272 SSPIOmitDomain Offˆà ˆà 273 SSPIBasicPreferred Onˆà ˆà 274 Require valid-userˆà ˆà 275 </Location>ˆà ˆà 276 }}}ˆà ˆà 277 ˆà ˆà 278 Using the above, usernames in Trac will be of the form `DOMAIN\username`, soˆà ˆà 279 you may have to re-add permissions and such. If you do not want the domain toˆà ˆà 280 be part of the username, set `SSPIOmitDomain On` instead.ˆà ˆà 281 ˆà ˆà 282 Some common problems with SSPI authentication: [trac:#1055], [trac:#1168] and [trac:#3338].ˆà ˆà 283 ˆà ˆà 284 See also [trac:TracOnWindows/Advanced].ˆà ˆà 285 ˆà ˆà 286 === Using Apache authentication with the Account Manager plugin's Login form ===ˆà ˆà 287 ˆà ˆà 288 To begin with, see the basic instructions for using the Account Manager plugin's [http://trac-hacks.org/wiki/AccountManagerPlugin/Modules#LoginModule Login module] and its [http://trac-hacks.org/wiki/AccountManagerPlugin/AuthStores#HttpAuthStore HttpAuthStore authentication module].ˆà ˆà 289 ˆà ˆà 290 '''Note:''' If is difficult to get !HttpAuthStore to work with WSGI when using any Account Manager version prior to acct_mgr-0.4. Upgrading is recommended.ˆà ˆà 291 ˆà ˆà 292 Here is an example (from the !HttpAuthStore link) using acct_mgr-0.4 for hosting a single project:ˆà ˆà 293 {{{ˆà ˆà 294 [components]ˆà ˆà 295 ; be sure to enable the componentˆà ˆà 296 acct_mgr.http.HttpAuthStore = enabledˆà ˆà 297 ˆà ˆà 298 [account-manager]ˆà ˆà 299 ; configure the plugin to use a page that is secured with http authenticationˆà ˆà 300 authentication_url = /authFileˆà ˆà 301 password_store = HttpAuthStoreˆà ˆà 302 }}}ˆà ˆà 303 This will generally be matched with an Apache config like:ˆà ˆà 304 {{{ˆà ˆà 305 <Location /authFile>ˆà ˆà 306 òÀæHTTP authentication configurationòÀæˆà ˆà 307 Require valid-userˆà ˆà 308 </Location>ˆà ˆà 309 }}}ˆà ˆà 310 Note that '''authFile''' need not exist. See the !HttpAuthStore link above for examples where multiple Trac projects are hosted on a server.ˆà ˆà 311 ˆà ˆà 312 === Example: Apache/mod_wsgi with Basic Authentication, Trac being at the root of a virtual hostˆà ˆà 313 ˆà ˆà 314 Per the mod_wsgi documentation linked to above, here is an example Apache configuration that a) serves the Trac instance from a virtualhost subdomain and b) uses Apache basic authentication for Trac authentication.ˆà ˆà 315 ˆà ˆà 316 ˆà ˆà 317 If you want your Trac to be served from e.g. !http://trac.my-proj.my-site.org, then from the folder e.g. `/home/trac-for-my-proj`, if you used the command `trac-admin the-env initenv` to create a folder `the-env`, and you used `trac-admin the-env deploy the-deploy` to create a folder `the-deploy`, then first:ˆà ˆà 318 ˆà ˆà 319 Create the htpasswd file:ˆà ˆà 320 {{{ˆà ˆà 321 cd /home/trac-for-my-proj/the-envˆà ˆà 322 htpasswd -c htpasswd firstuserˆà ˆà 323 ### and add more users to it as needed:ˆà ˆà 324 htpasswd htpasswd seconduserˆà ˆà 325 }}}ˆà ˆà 326 (keep the file above your document root for security reasons)ˆà ˆà 327 ˆà ˆà 328 Create this file e.g. (ubuntu) `/etc/apache2/sites-enabled/trac.my-proj.my-site.org.conf` with the following contents:ˆà ˆà 329 ˆà ˆà 330 {{{ˆà ˆà 331 <Directory /home/trac-for-my-proj/the-deploy/cgi-bin/trac.wsgi>ˆà ˆà 332 WSGIApplicationGroup %{GLOBAL}ˆà ˆà 333 Order deny,allowˆà ˆà 334 Allow from allˆà ˆà 335 </Directory>ˆà ˆà 336 ˆà ˆà 337 <VirtualHost *:80>ˆà ˆà 338 ServerName trac.my-proj.my-site.orgˆà ˆà 339 DocumentRoot /home/trac-for-my-proj/the-env/htdocs/ˆà ˆà 340 WSGIScriptAlias / /home/trac-for-my-proj/the-deploy/cgi-bin/trac.wsgiˆà ˆà 341 <Location '/'>ˆà ˆà 342 AuthType Basicˆà ˆà 343 AuthName "Trac"ˆà ˆà 344 AuthUserFile /home/trac-for-my-proj/the-env/htpasswdˆà ˆà 345 Require valid-userˆà ˆà 346 </Location>ˆà ˆà 347 </VirtualHost>ˆà ˆà 348 ˆà ˆà 349 }}}ˆà ˆà 350 ˆà ˆà 351 Note: for subdomains to work you would probably also need to alter `/etc/hosts` and add A-Records to your host's DNS.ˆà ˆà 352 ˆà ˆà 353 ˆà ˆà 354 == Troubleshootingˆà ˆà 355 ˆà ˆà 356 === Use a recent versionˆà ˆà 357 ˆà ˆà 358 Please use either version 1.6, 2.4 or later of `mod_wsgi`. Versions prior to 2.4 in the 2.X branch have problems with some Apache configurations that use WSGI file wrapper extension. This extension is used in Trac to serve up attachments and static media files such as style sheets. If you are affected by this problem attachments will appear to be empty and formatting of HTML pages will appear not to work due to style sheet files not loading properly. Another frequent symptom is that binary attachment downloads are truncated. See mod_wsgi tickets [http://code.google.com/p/modwsgi/issues/detail?id=100 #100] and [http://code.google.com/p/modwsgi/issues/detail?id=132 #132].ˆà 73 359 ˆà 74 360 ''Note: using mod_wsgi 2.5 and Python 2.6.1 gave an Internal Server Error on my system (Apache 2.2.11 and Trac 0.11.2.1). Upgrading to Python 2.6.2 (as suggested [http://www.mail-archive.com/modwsgi@googlegroups.com/msg01917.html here]) solved this for me[[BR]]-- Graham Shanks''ˆà 75 361 ˆà 76 ˆà == Trac with PostgreSQL ==ˆà 77 ˆà ˆà 78 ˆà When using the mod_wsgi adapter with multiple Trac instances and PostgreSQL (or MySQL?) as a database back-end the server can get a lot of open database connections. (and thus PostgreSQL processes)ˆà 79 ˆà ˆà 80 ˆà A workable solution is to disabled connection pooling in Trac. This is done by setting poolable = False in trac.db.postgres_backend on the PostgreSQLConnection class.ˆà 81 ˆà ˆà 82 ˆà But it's not necessary to edit the source of trac, the following lines in trac.wsgi will also work:ˆà 83 ˆà ˆà 84 ˆà {{{ˆà 85 ˆà import trac.db.postgres_backendˆà 86 ˆà trac.db.postgres_backend.PostgreSQLConnection.poolable = Falseˆà 87 ˆà }}}ˆà 88 ˆà ˆà 89 ˆà Now Trac drops the connection after serving a page and the connection count on the database will be kept minimal.ˆà 90 ˆà ˆà 91 ˆà == Getting Trac to work nicely with SSPI and 'Require Group' ==ˆà ˆà 362 If you plan to use `mod_wsgi` in embedded mode on Windows or with the MPM worker on Linux, then you'll even need version 0.3.4 or greater (see [trac:#10675] for details).ˆà ˆà 363 ˆà ˆà 364 === Getting Trac to work nicely with SSPI and 'Require Group' ===ˆà 92 365 If like me you've set Trac up on Apache, Win32 and configured SSPI, but added a 'Require group' option to your apache configuration, then the SSPIOmitDomain option is probably not working. If its not working your usernames in trac are probably looking like 'DOMAIN\user' rather than 'user'.ˆà 93 366 ˆà 94 367 This WSGI script 'fixes' things, hope it helps:ˆà 95 ˆà {{{ ˆàˆà 368 {{{#!pythonˆà 96 369 import osˆà 97 370 import trac.web.mainˆà òÀæ òÀæ ˆà 105 378 return trac.web.main.dispatch_request(environ, start_response)ˆà 106 379 }}}ˆà ˆà 380 ˆà ˆà 381 ˆà ˆà 382 === Trac with PostgreSQL ===ˆà ˆà 383 ˆà ˆà 384 When using the mod_wsgi adapter with multiple Trac instances and PostgreSQL (or MySQL?) as a database back-end, the server ''may'' create a lot of open database connections and thus PostgreSQL processes.ˆà ˆà 385 ˆà ˆà 386 A somewhat brutal workaround is to disabled connection pooling in Trac. This is done by setting `poolable = False` in `trac.db.postgres_backend` on the `PostgreSQLConnection` class.ˆà ˆà 387 ˆà ˆà 388 But it's not necessary to edit the source of Trac, the following lines in `trac.wsgi` will also work:ˆà ˆà 389 ˆà ˆà 390 {{{ˆà ˆà 391 import trac.db.postgres_backendˆà ˆà 392 trac.db.postgres_backend.PostgreSQLConnection.poolable = Falseˆà ˆà 393 }}}ˆà ˆà 394 ˆà ˆà 395 orˆà ˆà 396 ˆà ˆà 397 {{{ˆà ˆà 398 import trac.db.mysql_backendˆà ˆà 399 trac.db.mysql_backend.MySQLConnection.poolable = Falseˆà ˆà 400 }}}ˆà ˆà 401 ˆà ˆà 402 Now Trac drops the connection after serving a page and the connection count on the database will be kept minimal.ˆà ˆà 403 ˆà ˆà 404 //This is not a recommended approach though. See also the notes at the bottom of the [http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac mod_wsgi's IntegrationWithTrac] wiki page.//ˆà ˆà 405 ˆà ˆà 406 === Other resourcesˆà ˆà 407 ˆà ˆà 408 For more troubleshooting tips, see also the [TracModPython#Troubleshooting mod_python troubleshooting] section, as most Apache-related issues are quite similar, plus discussion of potential [http://code.google.com/p/modwsgi/wiki/ApplicationIssues application issues] when using mod_wsgi. The wsgi page also has a [http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac Integration With Trac] document.ˆà ˆà 409 ˆà ˆà 410 ˆà 107 411 ----ˆà 108 412 See also: TracGuide, TracInstall, [wiki:TracFastCgi FastCGI], [wiki:TracModPython ModPython], [trac:TracNginxRecipe TracNginxRecipe]ˆà