| 50 | | Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, you may use the `TRAC_ENV_PARENT_DIR` variable instead of `TRAC_ENV` as described above. |
| | 85 | Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, you may use the `TRAC_ENV_PARENT_DIR` variable instead of `TRAC_ENV` as described above, |
| | 86 | and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf` |
| | 87 | using `bin-environment` (as in the section above on Apache configuration). |
| | 88 | |
| | 89 | For using two projects with lighttpd add the following to your `lighttpd.conf`: |
| | 90 | {{{ |
| | 91 | fastcgi.server = ("/first" => |
| | 92 | ("first" => |
| | 93 | ("socket" => "/tmp/trac-fastcgi-first.sock", |
| | 94 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| | 95 | "check-local" => "disable", |
| | 96 | "bin-environment" => |
| | 97 | ("TRAC_ENV" => "/path/to/projenv-first") |
| | 98 | ) |
| | 99 | ), |
| | 100 | "/second" => |
| | 101 | ("second" => |
| | 102 | ("socket" => "/tmp/trac-fastcgi-second.sock", |
| | 103 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| | 104 | "check-local" => "disable", |
| | 105 | "bin-environment" => |
| | 106 | ("TRAC_ENV" => "/path/to/projenv-second") |
| | 107 | ) |
| | 108 | ) |
| | 109 | ) |
| | 110 | }}} |
| | 111 | Note that field values are different. If you prefer setting the environment |
| | 112 | variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to |
| | 113 | `first.fcgi` and `second.fcgi`, and reference them in the above settings. |
| | 114 | Note that the above will result in different processes in any event, even |
| | 115 | if both are running from the same `trac.fcgi` script. |
| | 116 | {{{ |
| | 117 | #!html |
| | 118 | <p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;"> |
| | 119 | <strong>Note from c00i90wn:</strong> It's very important the order on which server.modules are loaded, if mod_auth is not loaded <strong>BEFORE</strong> mod_fastcgi, then the server will fail to authenticate the user. |
| | 120 | </p> |
| | 121 | }}} |
| | 122 | For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules: |
| | 123 | {{{ |
| | 124 | server.modules = ( |
| | 125 | ... |
| | 126 | "mod_auth", |
| | 127 | ... |
| | 128 | ) |
| | 129 | |
| | 130 | auth.backend = "htpasswd" |
| | 131 | |
| | 132 | # Separated password files for each project |
| | 133 | # See "Conditional Configuration" in |
| | 134 | # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt |
| | 135 | |
| | 136 | $HTTP["url"] =~ "^/first/" { |
| | 137 | auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess" |
| | 138 | } |
| | 139 | $HTTP["url"] =~ "^/second/" { |
| | 140 | auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess" |
| | 141 | } |
| | 142 | |
| | 143 | # Enable auth on trac URLs, see |
| | 144 | # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt |
| | 145 | |
| | 146 | auth.require = ("/first/login" => |
| | 147 | ("method" => "basic", |
| | 148 | "realm" => "First project", |
| | 149 | "require" => "valid-user" |
| | 150 | ), |
| | 151 | "/second/login" => |
| | 152 | ("method" => "basic", |
| | 153 | "realm" => "Second project", |
| | 154 | "require" => "valid-user" |
| | 155 | ) |
| | 156 | ) |
| | 157 | |
| | 158 | |
| | 159 | }}} |
| | 160 | Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist. |
| | 161 | |
| | 162 | Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16. |
| | 163 | |
| | 164 | Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI: |
| | 165 | {{{ |
| | 166 | # Aliasing functionality is needed |
| | 167 | server.modules += ("mod_alias") |
| | 168 | |
| | 169 | # Setup an alias for the static resources |
| | 170 | alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs") |
| | 171 | |
| | 172 | # Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in |
| | 173 | # /trac/chrome/common, and use FastCGI for those |
| | 174 | $HTTP["url"] =~ "^/trac(?!/chrome/common)" { |
| | 175 | # If you have previous fastcgi.server declarations for applications other than Trac, use += here |
| | 176 | # instead of = so you won't overwrite them |
| | 177 | fastcgi.server = ("/trac" => |
| | 178 | ("trac" => |
| | 179 | ("socket" => "/tmp/trac-fastcgi.sock", |
| | 180 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| | 181 | "check-local" => "disable", |
| | 182 | "bin-environment" => |
| | 183 | ("TRAC_ENV" => "/path/to/projenv") |
| | 184 | ) |
| | 185 | ) |
| | 186 | ) |
| | 187 | } |
| | 188 | }}} |
| | 189 | 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. |
| | 190 | 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: |
| | 191 | {{{ |
| | 192 | # This is for handling multiple projects |
| | 193 | alias.url = ( "/trac/" => "/path/to/trac/htdocs/" ) |
| | 194 | |
| | 195 | fastcgi.server += ("/projects" => |
| | 196 | ("trac" => |
| | 197 | ( |
| | 198 | "socket" => "/tmp/trac.sock", |
| | 199 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| | 200 | "check-local" => "disable", |
| | 201 | "bin-environment" => |
| | 202 | ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) |
| | 203 | ) |
| | 204 | ) |
| | 205 | ) |
| | 206 | #And here starts the global auth configuration |
| | 207 | auth.backend = "htpasswd" |
| | 208 | auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" |
| | 209 | $HTTP["url"] =~ "^/projects/.*/login$" { |
| | 210 | auth.require = ("/" => |
| | 211 | ( |
| | 212 | "method" => "basic", |
| | 213 | "realm" => "trac", |
| | 214 | "require" => "valid-user" |
| | 215 | ) |
| | 216 | ) |
| | 217 | } |
| | 218 | }}} |
| | 219 | |
| | 220 | Changing date/time format also supported by lighttpd over environment variable LC_TIME |
| | 221 | {{{ |
| | 222 | fastcgi.server = ("/trac" => |
| | 223 | ("trac" => |
| | 224 | ("socket" => "/tmp/trac-fastcgi.sock", |
| | 225 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| | 226 | "check-local" => "disable", |
| | 227 | "bin-environment" => |
| | 228 | ("TRAC_ENV" => "/path/to/projenv", |
| | 229 | "LC_TIME" => "ru_RU") |
| | 230 | ) |
| | 231 | ) |
| | 232 | ) |
| | 233 | }}} |
| | 234 | For details about languages specification see TracFaq question 2.13. |