tracfastcgi
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | tracfastcgi [2015/06/09 15:23] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Trac with FastCGI ====== | ||
+ | |||
+ | Since version 0.9, Trac supports being run through the [[http:// | ||
+ | |||
+ | ===== Simple Apache configuration ===== | ||
+ | |||
+ | There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and | ||
+ | `mod_fcgid`. | ||
+ | below are `mod_fastcgi` directives; the `DefaultInitEnv` is a `mod_fgcid` | ||
+ | directive. | ||
+ | |||
+ | For `mod_fastcgi`, | ||
+ | file: | ||
+ | < | ||
+ | # Enable fastcgi for .fcgi files | ||
+ | # (If you're using a distro package for mod_fcgi, something like | ||
+ | # this is probably already present) | ||
+ | < | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | LoadModule fastcgi_module / | ||
+ | </ | ||
+ | |||
+ | Setting `FastCgiIpcDir` is optional if the default is suitable. Note that the `LoadModule` line must be after the `IfModule` group. | ||
+ | |||
+ | Configure `ScriptAlias` or similar options as described in TracCgi, but | ||
+ | calling `trac.fcgi` instead of `trac.cgi`. | ||
+ | |||
+ | You can set up the `TRAC_ENV` as an overall default: | ||
+ | < | ||
+ | FastCgiConfig -initial-env TRAC_ENV=/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | Or you can serve multiple Trac projects in a directory like: | ||
+ | < | ||
+ | FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | But neither of these will work for `mod_fcgid`. | ||
+ | solution for `mod_fcgid` is: | ||
+ | < | ||
+ | DefaultInitEnv TRAC_ENV / | ||
+ | </ | ||
+ | |||
+ | But this cannot be used in `Directory` or `Location` context, which makes it | ||
+ | difficult to support multiple projects. | ||
+ | |||
+ | A better method which works for both of these modules (and for [[http:// | ||
+ | no server configuration settings for environment variables, is to set one | ||
+ | of the variables in `trac.fcgi`, | ||
+ | < | ||
+ | import os | ||
+ | os.environ[[:' | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | < | ||
+ | import os | ||
+ | os.environ[[:' | ||
+ | </ | ||
+ | |||
+ | |||
+ | Using this method, different projects can be supported by using different | ||
+ | `.fcgi` scripts with different `ScriptAliases`, | ||
+ | renaming `trac.fcgi` and adding the above code to create each such script. | ||
+ | |||
+ | ===== Simple Lighttpd Configuration ===== | ||
+ | |||
+ | The FastCGI front-end was developed primarily for use with alternative webservers, such as [[http:// | ||
+ | |||
+ | lighttpd is a secure, fast, compliant and very flexible web-server that has been optimized for high-performance | ||
+ | environments. | ||
+ | |||
+ | For using `trac.fcgi` with lighttpd add the following to your lighttpd.conf: | ||
+ | < | ||
+ | fastcgi.server = ("/ | ||
+ | | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | (" | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | |||
+ | Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, | ||
+ | and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf` | ||
+ | using `bin-environment` (as in the section above on Apache configuration). | ||
+ | |||
+ | For using two projects with lighttpd add the following to your `lighttpd.conf`: | ||
+ | < | ||
+ | fastcgi.server = ("/ | ||
+ | | ||
+ | (" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | ) | ||
+ | ), | ||
+ | "/ | ||
+ | (" | ||
+ | (" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | Note that field values are different. | ||
+ | variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, | ||
+ | `first.fcgi` and `second.fcgi`, | ||
+ | Note that the above will result in different processes in any event, even | ||
+ | if both are running from the same `trac.fcgi` script. | ||
+ | < | ||
+ | #!html | ||
+ | <p style=" | ||
+ | < | ||
+ | </p> | ||
+ | </ | ||
+ | |||
+ | For authentication you should enable mod_auth in lighttpd.conf ' | ||
+ | < | ||
+ | server.modules | ||
+ | ... | ||
+ | " | ||
+ | ... | ||
+ | ) | ||
+ | |||
+ | auth.backend | ||
+ | |||
+ | # Separated password files for each project | ||
+ | # See " | ||
+ | # http:// | ||
+ | |||
+ | $HTTP[[:" | ||
+ | auth.backend.htpasswd.userfile = "/ | ||
+ | } | ||
+ | $HTTP[[:" | ||
+ | auth.backend.htpasswd.userfile = "/ | ||
+ | } | ||
+ | |||
+ | # Enable auth on trac URLs, see | ||
+ | # http:// | ||
+ | |||
+ | auth.require = ("/ | ||
+ | (" | ||
+ | " | ||
+ | " | ||
+ | ), | ||
+ | "/ | ||
+ | (" | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | ) | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Note that lighttpd (I use version 1.4.3) stopped if password file doesn' | ||
+ | |||
+ | Note that lighttpd doesn' | ||
+ | |||
+ | Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI: | ||
+ | < | ||
+ | # Aliasing functionality is needed | ||
+ | server.modules += (" | ||
+ | |||
+ | # Setup an alias for the static resources | ||
+ | alias.url = ("/ | ||
+ | |||
+ | # Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in | ||
+ | # / | ||
+ | $HTTP[[:" | ||
+ | # Even if you have other fastcgi.server declarations for applications other than Trac, do NOT use += here | ||
+ | fastcgi.server = ("/ | ||
+ | | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | (" | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The technique can be easily adapted for use with multiple projects by creating aliases for each of them, and wrapping the fastcgi.server declarations inside conditional configuration blocks. | ||
+ | Also there is another way to handle multiple projects and it's to use TRAC_ENV_PARENT_DIR instead of TRAC_ENV and use global auth, let's see an example: | ||
+ | < | ||
+ | # This is for handling multiple projects | ||
+ | alias.url | ||
+ | |||
+ | fastcgi.server += ("/ | ||
+ | (" | ||
+ | ( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | (" | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | #And here starts the global auth configuration | ||
+ | auth.backend = " | ||
+ | auth.backend.htpasswd.userfile = "/ | ||
+ | $HTTP[[:" | ||
+ | auth.require = ("/" | ||
+ | ( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | ) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | Changing date/time format also supported by lighttpd over environment variable LC_TIME | ||
+ | < | ||
+ | fastcgi.server = ("/ | ||
+ | | ||
+ | | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | (" | ||
+ | " | ||
+ | ) | ||
+ | ) | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | For details about languages specification see TracFaq question 2.13. | ||
+ | |||
+ | Other important information like [[http:// | ||
+ | |||
+ | If you use trac-0.9, read [[http:// | ||
+ | |||
+ | Relaunch lighttpd, and browse to `http:// | ||
+ | |||
+ | Note about running lighttpd with reduced permissions: | ||
+ | |||
+ | If nothing else helps and trac.fcgi doesn' | ||
+ | |||
+ | |||
+ | ===== Simple LiteSpeed Configuration ===== | ||
+ | |||
+ | The FastCGI front-end was developed primarily for use with alternative webservers, such as [[http:// | ||
+ | |||
+ | LiteSpeed web server is an event-driven asynchronous Apache replacement designed from the ground-up to be secure, scalable, and operate with minimal resources. LiteSpeed can operate directly from an Apache config file and is targeted for business-critical environments. | ||
+ | |||
+ | Setup | ||
+ | |||
+ | 1) Please make sure you have first have a working install of a Trac project. Test install with “tracd” first. | ||
+ | |||
+ | 2) Create a Virtual Host for this setup. From now on we will refer to this vhost as TracVhost. For this tutorial we will be assuming that your trac project will be accessible via: | ||
+ | |||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | 3) Go “TracVhost → External Apps” tab and create a new “External Application”. | ||
+ | |||
+ | < | ||
+ | Name: MyTracFCGI | ||
+ | Address: uds:// | ||
+ | Max Connections: | ||
+ | Environment: | ||
+ | Initial Request Timeout (secs): 30 | ||
+ | Retry Timeout (secs): 0 | ||
+ | Persistent Connection Yes | ||
+ | Connection Keepalive Timeout: 30 | ||
+ | Response Bufferring: No | ||
+ | Auto Start: Yes | ||
+ | Command: / | ||
+ | Back Log: 50 | ||
+ | Instances: 10 | ||
+ | </ | ||
+ | |||
+ | |||
+ | 4) Optional. If you need to use htpasswd based authentication. Go to “TracVhost → Security” tab and create a new security “Realm”. | ||
+ | |||
+ | < | ||
+ | DB Type: Password File | ||
+ | Realm Name: MyTracUserDB | ||
+ | User DB Location: / | ||
+ | </ | ||
+ | |||
+ | |||
+ | If you don’t have a htpasswd file or don’t know how to create the entries within one, go to http:// | ||
+ | |||
+ | 5) Go to “PythonVhost → Contexts” and create a new “FCGI Context”. | ||
+ | |||
+ | < | ||
+ | URI: / | ||
+ | Fast CGI App: [[: | ||
+ | Realm: TracUserDB | ||
+ | </ | ||
+ | |||
+ | |||
+ | 6) Modify / | ||
+ | |||
+ | < | ||
+ | #find/set base_rul, url, and link variables | ||
+ | base_url = http:// | ||
+ | url = http:// | ||
+ | link = http:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | 7) Restart LiteSpeed, “lswsctrl restart”, and access your new Trac project at: | ||
+ | |||
+ | < | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | See also TracCgi, TracModPython, | ||
tracfastcgi.txt · Last modified: 2015/06/09 15:23 by 127.0.0.1