Edgewall Software

Changes between Initial Version and Version 1 of TracNginxRecipe


Ignore:
Timestamp:
Nov 28, 2006, 11:22:58 PM (17 years ago)
Author:
joshland@…
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracNginxRecipe

    v1 v1  
     1= Using Tracd with Nginx in Cluster Mode =
     2I am intensely dissatisfied with Trac and Apache.  We have multiple vhosts, and multiple trac sites per vhost.  When we tried upgrading form Subverison 1.2.3 we hit [http://trac.edgewall.org/ticket/2611# this bug].
     3 * apache/mod_python still occasionally segfaults.
     4 * apache/mod_python was causing strange occasional delays. (Likely related to the segfaults).
     5 * We would like to upgrade to SVN 1.4
     6
     7'''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.
     8
     9== Tracd ==
     10Run multiple tracd instances.  This offers a speed benefit if you use [http://fasterfox.mozdev.org/ FasterFox], as well as good multi-user concurrency responsiveness.
     11
     12Using 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
     13
     14`start-meta-site.sh`
     15{{{
     16#!sh
     17INSTANCES="3050 3051 3052 3053 3054 3055 3056"
     18USER="apache"
     19VERSION="0.10.1"
     20#ENV="/var/live/trac"
     21PIDFILE="/var/live/run/tracd"
     22### Extra Args here, for instance --basic-auth
     23#ARGS="--basic-auth=${ENV},${ENV}/vccbob.pwd,FarQ"
     24ARGS="-e /var/live/trac"
     25PYTHON_EGG_CACHE="/var/live/egg_cache"
     26
     27function start(){
     28    export PYTHON_EGG_CACHE
     29    for I in $INSTANCES; do
     30        su ${USER} -c "/usr/bin/tracd -d -p ${I} --pidfile=${PIDFILE}.${I} --protocol=http ${ARGS} ${ENV}"
     31        done
     32}
     33
     34function stop(){
     35   for x in `ls ${PIDFILE}.*}`; do
     36       kill `cat ${x}`
     37       done
     38}
     39}}}
     40
     41`start-single-site.sh`
     42{{{
     43#!sh
     44INSTANCES="3050 3051 3052"
     45USER="apache"
     46VERSION="0.10.1"
     47ENV="/var/lib/trac-single"
     48PIDFILE="/var/lib/trac-single/run"
     49### Extra Args here, for instance --basic-auth
     50#ARGS="--basic-auth=${ENV},${ENV}/vccbob.pwd,FarQ"
     51ARGS="--basic-auth=${ENV},${ENV}/vccbob.pwd,FarQ ${ENV}"
     52PYTHON_EGG_CACHE="${ENV}/egg_cache"
     53
     54function start(){
     55    export PYTHON_EGG_CACHE
     56    for I in $INSTANCES; do
     57        su ${USER} -c "/usr/bin/tracd -d -p ${I} --pidfile=${PIDFILE}.${I} --protocol=http ${ARGS} ${ENV}"
     58        done
     59}
     60
     61function stop(){
     62   for x in `ls ${PIDFILE}.*}`; do
     63       kill `cat ${x}`
     64       done
     65}
     66
     67
     68}}}
     69
     70== Nginx ==
     71Get [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.
     72
     73/etc/nginx/nginx.conf
     74{{{
     75http {
     76  include         /etc/nginx/mime.types;
     77  default_type    application/octet-stream;
     78
     79  include         /etc/nginx/nginx-defaults.conf;
     80
     81  upstream live_trachosts_com {
     82          server  127.0.0.1:3050;
     83          server  127.0.0.1:3051;
     84          #[... up to the number of instance, or more, if you want to be free to add more ...]
     85  }
     86 
     87  server {
     88          listen          192.168.1.254:80;
     89          server_name     live.trachosts.com live;
     90 
     91          access_log      /var/log/nginx/live.access.log main;
     92          error_log       /var/log/nginx/live.error_log info;
     93 
     94          location / {
     95                  proxy_pass      http://live_trachosts_com;
     96                  include         /etc/nginx/proxy.conf;
     97          }
     98 
     99  }
     100}}}
     101
     102== Nginx + SSL ==
     103You might be asking about ssl - here is what we do for ssl:
     104/etc/nginx/nginx.conf
     105{{{
     106http {
     107  include         /etc/nginx/mime.types;
     108  default_type    application/octet-stream;
     109
     110  include         /etc/nginx/nginx-defaults.conf;
     111
     112  upstream live_trachosts_com {
     113          server  127.0.0.1:3050;
     114          server  127.0.0.1:3051;
     115          #[... up to the number of instance, or more, if you want to be free to add more ...]
     116  }
     117 
     118  server {
     119          listen          192.168.1.254:80;
     120          server_name     live.trachosts.com live;
     121 
     122          access_log      /var/log/nginx/live.access.log main;
     123          error_log       /var/log/nginx/live.error_log info;
     124 
     125          location / {
     126                  rewrite         ^/(.*)$ https://imrlive.com/$1 redirect;
     127          }
     128 
     129  }
     130  server {
     131          listen          192.168.1.254:443;
     132          server_name     live.trachosts.com live;
     133 
     134          access_log      /var/log/nginx/live.access.log main;
     135          error_log       /var/log/nginx/live.error_log info;
     136 
     137          ssl                  on;
     138          ssl_certificate      /etc/nginx/ssl/_nginx.cert;
     139          ssl_certificate_key  /etc/nginx/ssl/traclive.key;
     140          keepalive_timeout    70;
     141          add_header           Front-End-Https    on;
     142
     143          location / {
     144                  proxy_pass      http://live_trachosts_com;
     145                  include         /etc/nginx/proxy.conf;
     146          }
     147 
     148  }
     149}
     150}}}
     151
     152
     153== Subversion ==
     154 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.
     155
     156{{{
     157Listen 127.0.0.1:80
     158<VirtualHost *:80>
     159    ServerAdmin webmaster@trachosts.com
     160    ServerName trachosts.com
     161    DocumentRoot "/var/www/live.trachosts.com/htdocs"
     162
     163    <Directory "/var/www/live.trachosts.com/htdocs">
     164        Options FollowSymLinks
     165        AllowOverride None
     166        Order allow,deny
     167        Allow from all
     168    </Directory>
     169
     170  # Subversion Configuration
     171  <IfModule mod_dav_svn.c>
     172      <Location /svn>
     173          DAV svn
     174          SVNParentPath /var/live/svn
     175          AuthType Basic
     176          AuthName "Client Trac Sites - Subversion Repository"
     177          AuthUserFile /var/live/conf/users
     178           <IfModule !mod_authz_svn.c>
     179              AuthzSVNAccessFile /var/live/conf/svnauthz
     180          </IfModule>
     181          Require valid-user
     182      </Location>
     183  </IfModule>
     184</VirtualHost>
     185}}}
     186
     187Add this to the server section of the Nginx config. (in the :80 line, or the :443, whatever)
     188{{{
     189location /svn {
     190        proxy_pass      http://127.0.0.1:80;
     191        include         /etc/nginx/proxy.conf;
     192}
     193}}}
     194}}}