1 | | = How to use Nginx as your main web server for multiple Trac Projects = |
2 | | |
3 | | This recipe below is actually a very simple set up but the instructions did not make it obvious so let me explain. This set up is perfect if you use Nginx as your main webserver. First you set up Nginx as your main web server. Then you set up multiple instances of Tracd Web Server. (Trac has an embedded webserver that is included with Trac by default and this webserver is called Tracd.) Then you have Nginx serve requests to your Tracd web server instances. |
4 | | |
5 | | == Why you should use Tracd behind Nginx == |
| 1 | = Using Nginx as your main web server for multiple Trac Projects |
| 2 | |
| 3 | This recipe below is actually a very simple setup but the instructions did not make it obvious. This setup is perfect if you use Nginx as your main webserver. First you set up Nginx as your main web server and then you set up multiple instances of Tracd Web Server. Trac has an embedded webserver that is included in Trac and called Tracd. Then you have Nginx serve requests to your Tracd web server instances. |
| 4 | |
| 5 | == Why you should use Tracd behind Nginx |
11 | | 1. Set up Nginx as your main webserver (on port 80) |
12 | | 2. Start multiple instances of the Tracd embedded web server on different ports for each Trac Project |
13 | | 3. Configure Nginx to serve requests to your various running instances of Tracd Webserver. |
14 | | |
15 | | = Using Tracd with Nginx in Cluster Mode = |
16 | | I am intensely dissatisfied with Trac and Apache. We have multiple vhosts, and multiple trac sites per vhost. When we tried upgrading from Subversion 1.2.3 we hit [ticket:2611 this bug]. |
| 11 | 1. Set up Nginx as your main webserver on port 80. |
| 12 | 1. Start multiple instances of the Tracd embedded web server on different ports for each Trac Project. |
| 13 | 1. Configure Nginx to serve requests to your various running instances of Tracd Webserver. |
| 14 | |
| 15 | == Using Tracd with Nginx in Cluster Mode |
| 16 | I am intensely dissatisfied with Trac and Apache. We have multiple vhosts, and multiple Trac sites per vhost. When we tried upgrading from Subversion 1.2.3 we hit [ticket:2611 this bug]: |
21 | | '''Caveat''': Only use this with PostgreSQL. If you want to do this, but are on SQLite, then use Pacopablos [http://trac-hacks.org/wiki/SqliteToPgScript Sqlite-to-Pg]. We use it here, and it's great. |
22 | | |
23 | | == Tracd - Trac's light and fast embedded web server == |
24 | | Run multiple tracd instances. This offers a speed benefit if you use [http://fasterfox.mozdev.org/ FasterFox], as well as good multi-user concurrency responsiveness. |
25 | | |
26 | | Using the Gentoo init system, it was easy to create simple init scripts (which I attatched to this page). Here is a simplified example, which makes for easier wiki'ing |
27 | | |
28 | | |
29 | | '''Multi-Site tracd Startup'''[[br]] |
30 | | Works with trac-0.10 and up. |
| 21 | '''Caveat''': Only use this with PostgreSQL. If you want to do this, but are on SQLite, then use Pacopablos [http://trac-hacks.org/wiki/SqliteToPgScript Sqlite-to-Pg]. We use it here, and it's great. |
| 22 | |
| 23 | == Tracd - Trac's light and fast embedded web server |
| 24 | |
| 25 | Run multiple tracd instances. This offers a speed benefit if you use [http://fasterfox.mozdev.org/ FasterFox], as well as good concurrency responsiveness. |
| 26 | |
| 27 | Using the Gentoo init system, it was easy to create simple init scripts (which I attached to this page). Here is a simplified example, which makes for easier wiki'ing: |
| 28 | |
| 29 | '''Multi-Site tracd Startup''': works with Trac-0.10 and up: |
263 | | ---- |
264 | | |
265 | | Startup '''rc.d''' script for '''FreeBSD''' that allows you to run StandAlone server for '''multiple Trac Projects''' behind Nginx with '''ngx_http_proxy_module''' ''(proxy_pass)'' module.\\ |
266 | | This script better then default FreeBSD rc.d script because it’s smarter and supports multiple Trac Projects.\\ |
267 | | Also it supports '''authentication for each project separately''' with Trac basic authentication! |
268 | | |
269 | | `/usr/local/etc/rc.d/trac` |
| 260 | === FreeBSD |
| 261 | |
| 262 | Startup '''rc.d''' script for '''FreeBSD''' that allows you to run !StandAlone server for '''multiple Trac Projects''' behind Nginx with '''ngx_http_proxy_module''' ''(proxy_pass)'' module. |
| 263 | This script is better than the default FreeBSD rc.d script, because it supports multiple Trac Projects. |
| 264 | Also it supports '''authentication for each project separately''' with Trac basic authentication. |
| 265 | |
| 266 | `/usr/local/etc/rc.d/trac`: |
425 | | == Handling authentication in Nginx == |
426 | | |
427 | | If you want to handle the authentication in Nginx rather than trac, that is also possible. Since you are proxying the tracd server from Nginx, you just have to tell Nginx to forward the Authorization header to tracd, and be sure to use the same authentication scheme in both (Basic / Digest). Also, both Nginx and trac must access the same password file, or an identical copy. As a simple example, lets assume that you are using Basic authentication. Digest would be very similar. |
| 422 | == Handling authentication in Nginx |
| 423 | |
| 424 | If you want to handle the authentication in Nginx rather than trac, that is also possible. Since you are proxying the tracd server from Nginx, you just have to tell Nginx to forward the Authorization header to tracd, and be sure to use the same authentication scheme in both (Basic / Digest). Also, both Nginx and trac must access the same password file, or an identical copy. As a simple example, let's assume you are using Basic authentication. Digest would be very similar. |