# Trac static content
location ~ ^/trac/([0-9a-zA-Z\-_]*)/chrome(.*)$ {
        alias /var/www/trac/$1/htdocs$2;
}

# Trac FastCGI variables
# We can't get PATH_INFO from here, because NGINX does some
# urlencode magic FastCGI doesn't understand.
if ($uri ~ ^/trac/([0-9a-zA-Z\-_]*).*$) {
        set $trac_host $1;
}

# Trac FastCGI parameters
# This has to be a location regex, because otherwise the PHP interpreter would
# catch .php files.
location ~ ^/trac {
        auth_basic            "Trac";
        auth_basic_user_file  /etc/nginx/trac/trac.$trac_host.passwd;

        # This supplies us with $fastcgi_path_info, instead of our
        # if statement. (NGINX >= 0.7.31).
        fastcgi_split_path_info ^(/trac/[0-9a-zA-Z\-_]*[/]*)(.*)$;

        fastcgi_pass   unix:/var/run/trac-fastcgi-$trac_host.sock;
        fastcgi_param  HTTPS            on;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_param  SCRIPT_NAME      /trac/$trac_host;
        fastcgi_param  PATH_INFO        /$fastcgi_path_info;
        fastcgi_param  AUTH_USER        $remote_user;
        fastcgi_param  REMOTE_USER      $remote_user;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  SERVER_NAME      $server_name;
        fastcgi_param  SERVER_PORT      $server_port;
        fastcgi_param  SERVER_PROTOCOL  $server_protocol;
}
