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 | # Even if you have other fastcgi.server declarations for applications other than Trac, do NOT use += here |
| 176 | fastcgi.server = ("/trac" => |
| 177 | ("trac" => |
| 178 | ("socket" => "/tmp/trac-fastcgi.sock", |
| 179 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| 180 | "check-local" => "disable", |
| 181 | "bin-environment" => |
| 182 | ("TRAC_ENV" => "/path/to/projenv") |
| 183 | ) |
| 184 | ) |
| 185 | ) |
| 186 | } |
| 187 | }}} |
| 188 | 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. |
| 189 | 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: |
| 190 | {{{ |
| 191 | # This is for handling multiple projects |
| 192 | alias.url = ( "/trac/" => "/path/to/trac/htdocs/" ) |
| 193 | |
| 194 | fastcgi.server += ("/projects" => |
| 195 | ("trac" => |
| 196 | ( |
| 197 | "socket" => "/tmp/trac.sock", |
| 198 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| 199 | "check-local" => "disable", |
| 200 | "bin-environment" => |
| 201 | ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) |
| 202 | ) |
| 203 | ) |
| 204 | ) |
| 205 | #And here starts the global auth configuration |
| 206 | auth.backend = "htpasswd" |
| 207 | auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" |
| 208 | $HTTP["url"] =~ "^/projects/.*/login$" { |
| 209 | auth.require = ("/" => |
| 210 | ( |
| 211 | "method" => "basic", |
| 212 | "realm" => "trac", |
| 213 | "require" => "valid-user" |
| 214 | ) |
| 215 | ) |
| 216 | } |
| 217 | }}} |
| 218 | |
| 219 | Changing date/time format also supported by lighttpd over environment variable LC_TIME |
| 220 | {{{ |
| 221 | fastcgi.server = ("/trac" => |
| 222 | ("trac" => |
| 223 | ("socket" => "/tmp/trac-fastcgi.sock", |
| 224 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
| 225 | "check-local" => "disable", |
| 226 | "bin-environment" => |
| 227 | ("TRAC_ENV" => "/path/to/projenv", |
| 228 | "LC_TIME" => "ru_RU") |
| 229 | ) |
| 230 | ) |
| 231 | ) |
| 232 | }}} |
| 233 | For details about languages specification see TracFaq question 2.13. |
| 240 | |
| 241 | Note about running lighttpd with reduced permissions: |
| 242 | |
| 243 | If nothing else helps and trac.fcgi doesn't start with lighttpd settings __server.username = "www-data"__, __server.groupname = "www-data"__, then in the `bin-environment` section set `PYTHON_EGG_CACHE` to the home directory of `www-data` or some other directory accessible to this account for writing. |
| 244 | |
| 245 | |
| 246 | == Simple LiteSpeed Configuration == |
| 247 | |
| 248 | The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.litespeedtech.com/ LiteSpeed]. |
| 249 | |
| 250 | 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. |
| 251 | |
| 252 | Setup |
| 253 | |
| 254 | 1) Please make sure you have first have a working install of a Trac project. Test install with “tracd” first. |
| 255 | |
| 256 | 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: |
| 257 | |
| 258 | {{{ |
| 259 | http://yourdomain.com/trac/ |
| 260 | }}} |
| 261 | |
| 262 | 3) Go “TracVhost → External Apps” tab and create a new “External Application”. |
| 263 | |
| 264 | {{{ |
| 265 | Name: MyTracFCGI |
| 266 | Address: uds://tmp/lshttpd/mytracfcgi.sock |
| 267 | Max Connections: 10 |
| 268 | Environment: TRAC_ENV=/fullpathto/mytracproject/ <--- path to root folder of trac project |
| 269 | Initial Request Timeout (secs): 30 |
| 270 | Retry Timeout (secs): 0 |
| 271 | Persistent Connection Yes |
| 272 | Connection Keepalive Timeout: 30 |
| 273 | Response Bufferring: No |
| 274 | Auto Start: Yes |
| 275 | Command: /usr/share/trac/cgi-bin/trac.fcgi <--- path to trac.fcgi |
| 276 | Back Log: 50 |
| 277 | Instances: 10 |
| 278 | }}} |
| 279 | |
| 280 | 4) Optional. If you need to use htpasswd based authentication. Go to “TracVhost → Security” tab and create a new security “Realm”. |
| 281 | |
| 282 | {{{ |
| 283 | DB Type: Password File |
| 284 | Realm Name: MyTracUserDB <--- any name you wish and referenced later |
| 285 | User DB Location: /fullpathto/htpasswd <--- path to your htpasswd file |
| 286 | }}} |
| 287 | |
| 288 | If you don’t have a htpasswd file or don’t know how to create the entries within one, go to http://sherylcanter.com/encrypt.php, to generate the user:password combos. |
| 289 | |
| 290 | 5) Go to “PythonVhost → Contexts” and create a new “FCGI Context”. |
| 291 | |
| 292 | {{{ |
| 293 | URI: /trac/ <--- URI path to bind to python fcgi app we created |
| 294 | Fast CGI App: [VHost Level] MyTractFCGI <--- select the trac fcgi extapp we just created |
| 295 | Realm: TracUserDB <--- only if (4) is set. select ream created in (4) |
| 296 | }}} |
| 297 | |
| 298 | 6) Modify /fullpathto/mytracproject/conf/trac.ini |
| 299 | |
| 300 | {{{ |
| 301 | #find/set base_rul, url, and link variables |
| 302 | base_url = http://yourdomain.com/trac/ <--- base url to generate correct links to |
| 303 | url = http://yourdomain.com/trac/ <--- link of project |
| 304 | link = http://yourdomain.com/trac/ <--- link of graphic logo |
| 305 | }}} |
| 306 | |
| 307 | 7) Restart LiteSpeed, “lswsctrl restart”, and access your new Trac project at: |
| 308 | |
| 309 | {{{ |
| 310 | http://yourdomain.com/trac/ |
| 311 | }}} |