Edgewall Software

Version 6 (modified by shuuji3, 4 years ago) ( diff )

Fix typo filename and description

Install Trac on Ubuntu proxied by Nginx

This is a guide on how to install and run a single hosted Trac project from https://trac.edgewall.org with Nginx as the proxy server.

This guide should apply for the following Debian-based Linux distributions:

  • Debian 9
  • Ubuntu 16.04
  • Ubuntu 16.10
  • LinuxMint 18.1
  • LinuxMint 18.2

Here is a somewhat basic bash script for this. However, there will be some manual steps, but a find+replace will help a lot. Be aware you might run all of these commands with the sudo -H.

Notice: Remember to replace the https://trac-hacks.org/svn/fullblogplugin/0.11 with the plugin's latest verion.

apt-get install subversion libapache2-mod-python pypy python python-babel trac python-pip -y
pip install --upgrade pip
pip install --upgrade Babel
pip install --upgrade Trac
pip install --upgrade pillow
pip install dnspython
pip install spambayes
pip install oauth2
pip install httplib2
pip install TracTags
pip install TracSpamFilter 
pip install TracVote
easy_install --always-unzip https://trac-hacks.org/svn/fullblogplugin/0.11
mkdir -p /var/www/trac/

trac-admin /var/www/trac initenv

Follow the trac-admin guide.

Now let's test the Trac installation before we do anything else:

tracd --port 8000 /var/www/trac
lynx localhost:8000/trac

If it's working, then it's time to setup an admin user and password for the admin account. If it doesn't work, then that is beyond this wiki and you'll need to consult internet resources for a solution.

Run the following to create the admin user:

htpasswd -c /var/www/trac/.htpasswd adminusername
trac-admin /var/www/trac/ permission add adminusername TRAC_ADMIN

Replace adminusername with your desired username.

Next we set the proper user and group permissions on the Trac folder to allow the Nginx/Apache/Trac server to access it:

chown -R UserName:GroupName /var/www/trac/
chmod -R 775 /var/www/trac/

Preparation to Enable Git source

To enable git source browsing via Admin we need another subfolder:

mkdir -p /var/www/trac/git

Systemd startup script

In your /etc/systemd/system/ make this new file:

nano /etc/systemd/system/tracd.service

Then add the following to your tracd.service file:

Description = Trac Daemon
After = network.target

ExecStart = /usr/local/bin/tracd -p 3050 --protocol=http --basic-auth="*,/var/www/trac/.htpasswd,Restricted" -s /var/www/trac
Type = simple
User = UserName
Group = GroupName

WantedBy = multi-user.target

Nginx configuration

Now it's time to do the Nginx configuration. First we have to make a reverse proxy to the Trac daemon we have made in Systemd startup script.

In the /etc/nginx/nginx.conf we'll have to add a upstream for our reverse_proxy to Trac:

  upstream live_trachosts_com {

Now make the site.conf file in your preferred location, which by default would be /etc/nginx/conf.d/, otherwise it would be in /etc/nginx/sites-available but we go with the default nano /etc/nginx/conf.d/site.conf:

server {
  server_name  trac.local;
  charset utf8;
  access_log  /var/log/nginx/trac.access.log;
  error_log  /var/log/nginx/trac.debug.log;

  location / {
    proxy_pass  http://live_trachosts_com;
    proxy_set_header Host $host;
  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   /usr/share/nginx/html;

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  location ~ /\.ht {
      deny  all;


If you are using Apache as the webserver, then run the following:

a2enmod python
nano /etc/apache2/sites-available/trac.conf

It should have the following content:

 ServerName trac.local
 <Location />
  SetHandler mod_python
  PythonInterpreter main_interpreter
  PythonHandler trac.web.modpython_frontend
  PythonOption TracEnv /var/www/trac
  PythonOption TracEnvParentDir /var/www/trac
  PythonOption TracUriRoot /
  PythonOption TracEnv /var/www/trac
  # PythonOption TracEnvIndexTemplate /var/www/trac/templates/index-template.html
  PythonOption TracLocale en_US.UTF8
  PythonOption PYTHON_EGG_CACHE /tmp
  Order allow,deny
  Allow from all
 <Location /login>
  AuthType Basic
  AuthName "myproject"
  AuthUserFile /var/www/trac/.htpasswd
  Require valid-user

To enable the Trac site run a2ensite trac.conf.


The following paths is to be replaced with your preferences:

  • /var/www/trac: /full/path/to/trac
  • adminusername: YourUserName to be used as the Trac admin
  • UserName: The username for which the Trac daemon runs as, for example Your login UserName
  • GroupName: The group name for which the Trac daemon runs as, for example www-data
  • trac.local: full.domain.tld
  • live_trachosts_com: to what suits your needs
  • if you are running both Nginx and Apache on port 80/443, then you'll need to set the IP, but if you only run Nginx or Apache you can delete the IP address to listen on all addresses


In this tutorial I have used the following software versions:

$ uname -a
Linux hostname 4.11.0-14-generic #20~16.04.1-Ubuntu SMP Wed Aug 9 09:06:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ tracd --version
tracd 1.2.2
$ nginx -v
nginx version: nginx/1.13.6
Note: See TracWiki for help on using the wiki.