| 1 | = FastCGI로 Trac 운영하기 = |
---|
| 2 | |
---|
| 3 | 버전 0.9 이후에, Trac을 [http://www.fastcgi.com/ FastCGI] 인터페이스를 통해서 운영할 수 있습니다. [wiki:TracModPython mod_python]처럼, Trac을 resident 상태로 유지합니다. 그리고 각 요청에 대해서 새로운 프로세스를 시작해야만 하는 외부의 CGI 인터페이스에 비해서 빠릅니다. 그러나 mod_python과는 달리, [http://httpd.apache.org/docs/suexec.html SuEXEC]를 지원할 수 있습니다. 추가적으로 다양한 웹서버에 의해서 지원되어집니다. |
---|
| 4 | |
---|
| 5 | == 간단한 아파치 설정 == |
---|
| 6 | |
---|
| 7 | There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and |
---|
| 8 | `mod_fcgid`. The `FastCgiIpcDir` and `FastCgiConfig` directives discussed |
---|
| 9 | below are `mod_fastcgi` directives; the `DefaultInitEnv` is a `mod_fgcid` |
---|
| 10 | directive. |
---|
| 11 | |
---|
| 12 | For `mod_fastcgi`, add the following to an appropriate Apache configuration |
---|
| 13 | file: |
---|
| 14 | {{{ |
---|
| 15 | # Enable fastcgi for .fcgi files |
---|
| 16 | # (If you're using a distro package for mod_fcgi, something like |
---|
| 17 | # this is probably already present) |
---|
| 18 | <IfModule mod_fastcgi.c> |
---|
| 19 | AddHandler fastcgi-script .fcgi |
---|
| 20 | FastCgiIpcDir /var/lib/apache2/fastcgi |
---|
| 21 | </IfModule> |
---|
| 22 | LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so |
---|
| 23 | }}} |
---|
| 24 | Setting `FastCgiIpcDir` is optional if the default is suitable. Note that the `LoadModule` line must be after the `IfModule` group. |
---|
| 25 | |
---|
| 26 | Configure `ScriptAlias` or similar options as described in TracCgi, but |
---|
| 27 | calling `trac.fcgi` instead of `trac.cgi`. |
---|
| 28 | |
---|
| 29 | You can set up the `TRAC_ENV` as an overall default: |
---|
| 30 | {{{ |
---|
| 31 | FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac |
---|
| 32 | }}} |
---|
| 33 | |
---|
| 34 | 다음과 같이 하나의 디렉토리에 여러개의 Trac 프로젝트들을 설정할 수도 있습니다.: |
---|
| 35 | {{{ |
---|
| 36 | FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects |
---|
| 37 | }}} |
---|
| 38 | |
---|
| 39 | But neither of these will work for `mod_fcgid`. A similar but partial |
---|
| 40 | solution for `mod_fcgid` is: |
---|
| 41 | {{{ |
---|
| 42 | DefaultInitEnv TRAC_ENV /path/to/env/trac/ |
---|
| 43 | }}} |
---|
| 44 | But this cannot be used in `Directory` or `Location` context, which makes it |
---|
| 45 | difficult to support multiple projects. |
---|
| 46 | |
---|
| 47 | A better method which works for both of these modules (and for [http://www.lighttpd.net/ lighttpd] and CGI as well), because it involves |
---|
| 48 | no server configuration settings for environment variables, is to set one |
---|
| 49 | of the variables in `trac.fcgi`, e.g.: |
---|
| 50 | {{{ |
---|
| 51 | import os |
---|
| 52 | os.environ['TRAC_ENV'] = "/path/to/projectenv" |
---|
| 53 | }}} |
---|
| 54 | or |
---|
| 55 | {{{ |
---|
| 56 | import os |
---|
| 57 | os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir" |
---|
| 58 | }}} |
---|
| 59 | |
---|
| 60 | Using this method, different projects can be supported by using different |
---|
| 61 | `.fcgi` scripts with different `ScriptAliases`, copying and appropriately |
---|
| 62 | renaming `trac.fcgi` and adding the above code to create each such script. |
---|
| 63 | |
---|
| 64 | == 간단한 Lighttpd 설정 == |
---|
| 65 | |
---|
| 66 | FastCGI는 주로 [http://www.lighttpd.net/ lighttpd]같은 다른 웹서버에서 사용하기 위해서 개발되어졌습니다. |
---|
| 67 | |
---|
| 68 | 높은 성능의 환경에 대해 최적화되어 있는 lighttpd는 보안성, 속도, compliant가 뛰어나며 매우 유연한 웹서버입니다. lighttpd는 다른 웹서버와 비교해서 매우 작은 메모리와 CPU 부하를 가집니다. |
---|
| 69 | |
---|
| 70 | lighttpd와 같이 `trac.fcgi`를 사용하기 위해서는, lighttpd.conf 파일에 다음 내용을 추가하십시오.: |
---|
| 71 | {{{ |
---|
| 72 | fastcgi.server = ("/trac" => |
---|
| 73 | ("trac" => |
---|
| 74 | ("socket" => "/tmp/trac-fastcgi.sock", |
---|
| 75 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 76 | "check-local" => "disable", |
---|
| 77 | "bin-environment" => |
---|
| 78 | ("TRAC_ENV" => "/path/to/projenv") |
---|
| 79 | ) |
---|
| 80 | ) |
---|
| 81 | ) |
---|
| 82 | }}} |
---|
| 83 | |
---|
| 84 | 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 | and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf` |
---|
| 86 | using `bin-environment` (as in the section above on Apache configuration). |
---|
| 87 | |
---|
| 88 | For using two projects with lighttpd add the following to your `lighttpd.conf`: |
---|
| 89 | {{{ |
---|
| 90 | fastcgi.server = ("/first" => |
---|
| 91 | ("first" => |
---|
| 92 | ("socket" => "/tmp/trac-fastcgi-first.sock", |
---|
| 93 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 94 | "check-local" => "disable", |
---|
| 95 | "bin-environment" => |
---|
| 96 | ("TRAC_ENV" => "/path/to/projenv-first") |
---|
| 97 | ) |
---|
| 98 | ), |
---|
| 99 | "/second" => |
---|
| 100 | ("second" => |
---|
| 101 | ("socket" => "/tmp/trac-fastcgi-second.sock", |
---|
| 102 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 103 | "check-local" => "disable", |
---|
| 104 | "bin-environment" => |
---|
| 105 | ("TRAC_ENV" => "/path/to/projenv-second") |
---|
| 106 | ) |
---|
| 107 | ) |
---|
| 108 | ) |
---|
| 109 | }}} |
---|
| 110 | Note that field values are different. If you prefer setting the environment |
---|
| 111 | variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to |
---|
| 112 | `first.fcgi` and `second.fcgi`, and reference them in the above settings. |
---|
| 113 | Note that the above will result in different processes in any event, even |
---|
| 114 | if both are running from the same `trac.fcgi` script. |
---|
| 115 | {{{ |
---|
| 116 | #!html |
---|
| 117 | <p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;"> |
---|
| 118 | <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. |
---|
| 119 | </p> |
---|
| 120 | }}} |
---|
| 121 | For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules: |
---|
| 122 | {{{ |
---|
| 123 | server.modules = ( |
---|
| 124 | ... |
---|
| 125 | "mod_auth", |
---|
| 126 | ... |
---|
| 127 | ) |
---|
| 128 | |
---|
| 129 | auth.backend = "htpasswd" |
---|
| 130 | |
---|
| 131 | # Separated password files for each project |
---|
| 132 | # See "Conditional Configuration" in |
---|
| 133 | # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt |
---|
| 134 | |
---|
| 135 | $HTTP["url"] =~ "^/first/" { |
---|
| 136 | auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess" |
---|
| 137 | } |
---|
| 138 | $HTTP["url"] =~ "^/second/" { |
---|
| 139 | auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess" |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | # Enable auth on trac URLs, see |
---|
| 143 | # http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt |
---|
| 144 | |
---|
| 145 | auth.require = ("/first/login" => |
---|
| 146 | ("method" => "basic", |
---|
| 147 | "realm" => "First project", |
---|
| 148 | "require" => "valid-user" |
---|
| 149 | ), |
---|
| 150 | "/second/login" => |
---|
| 151 | ("method" => "basic", |
---|
| 152 | "realm" => "Second project", |
---|
| 153 | "require" => "valid-user" |
---|
| 154 | ) |
---|
| 155 | ) |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | }}} |
---|
| 159 | Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist. |
---|
| 160 | |
---|
| 161 | Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16. |
---|
| 162 | |
---|
| 163 | Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI: |
---|
| 164 | {{{ |
---|
| 165 | # Aliasing functionality is needed |
---|
| 166 | server.modules += ("mod_alias") |
---|
| 167 | |
---|
| 168 | # Setup an alias for the static resources |
---|
| 169 | alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs") |
---|
| 170 | |
---|
| 171 | # Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in |
---|
| 172 | # /trac/chrome/common, and use FastCGI for those |
---|
| 173 | $HTTP["url"] =~ "^/trac(?!/chrome/common)" { |
---|
| 174 | # Even if you have other fastcgi.server declarations for applications other than Trac, do NOT use += here |
---|
| 175 | fastcgi.server = ("/trac" => |
---|
| 176 | ("trac" => |
---|
| 177 | ("socket" => "/tmp/trac-fastcgi.sock", |
---|
| 178 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 179 | "check-local" => "disable", |
---|
| 180 | "bin-environment" => |
---|
| 181 | ("TRAC_ENV" => "/path/to/projenv") |
---|
| 182 | ) |
---|
| 183 | ) |
---|
| 184 | ) |
---|
| 185 | } |
---|
| 186 | }}} |
---|
| 187 | 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. |
---|
| 188 | 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: |
---|
| 189 | {{{ |
---|
| 190 | # This is for handling multiple projects |
---|
| 191 | alias.url = ( "/trac/" => "/path/to/trac/htdocs/" ) |
---|
| 192 | |
---|
| 193 | fastcgi.server += ("/projects" => |
---|
| 194 | ("trac" => |
---|
| 195 | ( |
---|
| 196 | "socket" => "/tmp/trac.sock", |
---|
| 197 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 198 | "check-local" => "disable", |
---|
| 199 | "bin-environment" => |
---|
| 200 | ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) |
---|
| 201 | ) |
---|
| 202 | ) |
---|
| 203 | ) |
---|
| 204 | #And here starts the global auth configuration |
---|
| 205 | auth.backend = "htpasswd" |
---|
| 206 | auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" |
---|
| 207 | $HTTP["url"] =~ "^/projects/.*/login$" { |
---|
| 208 | auth.require = ("/" => |
---|
| 209 | ( |
---|
| 210 | "method" => "basic", |
---|
| 211 | "realm" => "trac", |
---|
| 212 | "require" => "valid-user" |
---|
| 213 | ) |
---|
| 214 | ) |
---|
| 215 | } |
---|
| 216 | }}} |
---|
| 217 | |
---|
| 218 | Changing date/time format also supported by lighttpd over environment variable LC_TIME |
---|
| 219 | {{{ |
---|
| 220 | fastcgi.server = ("/trac" => |
---|
| 221 | ("trac" => |
---|
| 222 | ("socket" => "/tmp/trac-fastcgi.sock", |
---|
| 223 | "bin-path" => "/path/to/cgi-bin/trac.fcgi", |
---|
| 224 | "check-local" => "disable", |
---|
| 225 | "bin-environment" => |
---|
| 226 | ("TRAC_ENV" => "/path/to/projenv", |
---|
| 227 | "LC_TIME" => "ru_RU") |
---|
| 228 | ) |
---|
| 229 | ) |
---|
| 230 | ) |
---|
| 231 | }}} |
---|
| 232 | For details about languages specification see TracFaq question 2.13. |
---|
| 233 | |
---|
| 234 | Other important information like [http://trac.lighttpd.net/trac/wiki/TracInstall this updated TracInstall page], [wiki:TracCgi#MappingStaticResources and this] are useful for non-fastcgi specific installation aspects. |
---|
| 235 | |
---|
| 236 | If you use trac-0.9, read [http://lists.edgewall.com/archive/trac/2005-November/005311.html about small bug] |
---|
| 237 | |
---|
| 238 | Relaunch lighttpd, and browse to `http://yourhost.example.org/trac` to access Trac. |
---|
| 239 | |
---|
| 240 | Note about running lighttpd with reduced permissions: |
---|
| 241 | |
---|
| 242 | 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. |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | == Simple LiteSpeed Configuration == |
---|
| 246 | |
---|
| 247 | The FastCGI front-end was developed primarily for use with alternative webservers, such as [http://www.litespeedtech.com/ LiteSpeed]. |
---|
| 248 | |
---|
| 249 | 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. |
---|
| 250 | |
---|
| 251 | Setup |
---|
| 252 | |
---|
| 253 | 1) Please make sure you have first have a working install of a Trac project. Test install with “tracd” first. |
---|
| 254 | |
---|
| 255 | 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: |
---|
| 256 | |
---|
| 257 | {{{ |
---|
| 258 | http://yourdomain.com/trac/ |
---|
| 259 | }}} |
---|
| 260 | |
---|
| 261 | 3) Go “TracVhost → External Apps” tab and create a new “External Application”. |
---|
| 262 | |
---|
| 263 | {{{ |
---|
| 264 | Name: MyTracFCGI |
---|
| 265 | Address: uds://tmp/lshttpd/mytracfcgi.sock |
---|
| 266 | Max Connections: 10 |
---|
| 267 | Environment: TRAC_ENV=/fullpathto/mytracproject/ <--- path to root folder of trac project |
---|
| 268 | Initial Request Timeout (secs): 30 |
---|
| 269 | Retry Timeout (secs): 0 |
---|
| 270 | Persistent Connection Yes |
---|
| 271 | Connection Keepalive Timeout: 30 |
---|
| 272 | Response Bufferring: No |
---|
| 273 | Auto Start: Yes |
---|
| 274 | Command: /usr/share/trac/cgi-bin/trac.fcgi <--- path to trac.fcgi |
---|
| 275 | Back Log: 50 |
---|
| 276 | Instances: 10 |
---|
| 277 | }}} |
---|
| 278 | |
---|
| 279 | 4) Optional. If you need to use htpasswd based authentication. Go to “TracVhost → Security” tab and create a new security “Realm”. |
---|
| 280 | |
---|
| 281 | {{{ |
---|
| 282 | DB Type: Password File |
---|
| 283 | Realm Name: MyTracUserDB <--- any name you wish and referenced later |
---|
| 284 | User DB Location: /fullpathto/htpasswd <--- path to your htpasswd file |
---|
| 285 | }}} |
---|
| 286 | |
---|
| 287 | 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. |
---|
| 288 | |
---|
| 289 | 5) Go to “PythonVhost → Contexts” and create a new “FCGI Context”. |
---|
| 290 | |
---|
| 291 | {{{ |
---|
| 292 | URI: /trac/ <--- URI path to bind to python fcgi app we created |
---|
| 293 | Fast CGI App: [VHost Level] MyTractFCGI <--- select the trac fcgi extapp we just created |
---|
| 294 | Realm: TracUserDB <--- only if (4) is set. select ream created in (4) |
---|
| 295 | }}} |
---|
| 296 | |
---|
| 297 | 6) Modify /fullpathto/mytracproject/conf/trac.ini |
---|
| 298 | |
---|
| 299 | {{{ |
---|
| 300 | #find/set base_rul, url, and link variables |
---|
| 301 | base_url = http://yourdomain.com/trac/ <--- base url to generate correct links to |
---|
| 302 | url = http://yourdomain.com/trac/ <--- link of project |
---|
| 303 | link = http://yourdomain.com/trac/ <--- link of graphic logo |
---|
| 304 | }}} |
---|
| 305 | |
---|
| 306 | 7) Restart LiteSpeed, “lswsctrl restart”, and access your new Trac project at: |
---|
| 307 | |
---|
| 308 | {{{ |
---|
| 309 | http://yourdomain.com/trac/ |
---|
| 310 | }}} |
---|
| 311 | |
---|
| 312 | ---- |
---|
| 313 | 참고 : TracCgi, TracModPython, TracInstall, TracGuide |