Edgewall Software

Changes between Version 24 and Version 25 of TracNginxRecipe


Ignore:
Timestamp:
Jan 27, 2015, 7:50:58 PM (9 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracNginxRecipe

    v24 v25  
    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
     3This 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
    66
    77This is an easy set up which allows Nginx to act as an excellent load balancer.  Tracd is lightweight and fast and its easy to get working with your Trac projects.  You can start multiple instances of the Tracd web server on different ports for different Trac projects.  Nginx as your main webserver can serve requests to these various running instances of the Tracd web server.  This also works for multiple Trac Projects on multiple vhosts.  In short its fast, lightweight, and easy to set up.
     
    99Here are the steps you need to take.
    1010
    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
     16I 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]:
    1717 * apache/mod_python still occasionally segfaults.
    18  * apache/mod_python was causing strange occasional delays. (Likely related to the segfaults).
     18 * apache/mod_python was causing strange occasional delays, likely related to the segfaults.
    1919 * We would like to upgrade to SVN 1.4
    2020
    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
     25Run multiple tracd instances. This offers a speed benefit if you use [http://fasterfox.mozdev.org/ FasterFox], as well as good concurrency responsiveness.
     26
     27Using 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:
    3130
    3231`tracd -d -p 3050 --pidfile=/var/live/run/tracd.3050 --protocol=http -e /var/live/trac`
    3332
    34 '''Single-Site tracd Startup'''[[br]]
    35 ''note'': will not work with anything pre '''0.10'''.
     33'''Single-Site tracd Startup''': will not work with Trac before version '''0.10''':
    3634
    3735`tracd -d -p 3050 --pidfile=/var/live/run/tracd.3051 --protocol=http -s /var/live/trac/telecardia`
    3836
    39 
    40 == Nginx ==
    41 Get [http://www.nginx.net/ Nginx], the Excellent Apache Replacement by [http://sysoev.ru/en/ Igor Sysoev].  Install it.  I use Gentoo, and all of my examples are based on Gentoo.  Gentoo packagers create /etc/nginx.
    42 
    43 /etc/nginx/nginx.conf
     37== Nginx
     38
     39Install [http://www.nginx.net/ Nginx], the Excellent Apache Replacement by [http://sysoev.ru/en/ Igor Sysoev]. All examples are based on Gentoo and the Gentoo package is under /etc/nginx.
     40
     41Sample /etc/nginx/nginx.conf:
    4442{{{
    4543#!nginx
     
    7472}}}
    7573
    76 == Nginx + SSL ==
    77 You might be asking about ssl - here is what we do for ssl:
    78 /etc/nginx/nginx.conf
     74== Nginx + SSL
     75
     76Here is what we do for SSL in /etc/nginx/nginx.conf:
    7977{{{
    8078#!nginx
     
    128126}}}
    129127
    130 '''Static Content'''[[br]]
     128=== Static Content
     129
    131130Serving static files from htdocs dir ala /<site>/chrome/site aliases `http://live.trachosts.com/myproj/chrome/site` to `/var/trachosts/trac/myproj/htdocs`
    132131{{{
     
    139138}}}
    140139
    141 
    142 == Subversion ==
    143 
    144 This section isn't necessary if you're using tracd so long as you start tracd as follows.
    145 
     140== Subversion
     141
     142This section can be skiped if you're using tracd and start it as follows:
    146143{{{
    147144/usr/bin/python /usr/bin/tracd -d -p 3050 --basic-auth projec1,/var/www/trac/project1/db/users.htdigest,svn --pidfile=/var/www/trac/tracd.3050 --protocol=http -e /var/www/trac
    148145}}}
    149146
    150 We still need to get access to subversion via Apache mod_dav_svn.  I created a vhost in apache for _only_ the svn URLs.  Other people will not use this setup, which is good for them.
     147We still need to get access to subversion via Apache mod_dav_svn. I created a vhost in apache for _only_ the svn URLs. Other people might not use this setup.
    151148
    152149{{{
     
    187184}}}
    188185
    189 Add this to the server section of the Nginx config. (in the :80 line, or the :443, whatever)
     186Add this to the server section of the Nginx config, in the :80 line, or the :443:
    190187{{{
    191188#!nginx
     
    201198}}}
    202199
    203 == Script Examples ==
    204 
    205 `start-meta-site.sh`
     200== Script Examples
     201
     202`start-meta-site.sh`:
    206203{{{
    207204#!sh
     
    261258}}}
    262259
    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
     262Startup '''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.
     263This script is better than the default FreeBSD rc.d script, because it supports multiple Trac Projects.
     264Also it supports '''authentication for each project separately''' with Trac basic authentication.
     265
     266`/usr/local/etc/rc.d/trac`:
    270267{{{
    271268#!sh
     
    423420}}}
    424421
    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
     424If 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.
    428425
    429426This is the Nginx configuration snippet:
     
    453450
    454451== Todo ==
    455  * Post the actualy config files ''somewhere''.
     452 * Post the actual config files ''somewhere''.
    456453
    457454== Questions ==