Mark Garratt

Mark Garratt

Who am I?

Web Developer based in London, UK


What I write about


Recent Posts

Installing Ajenti with Nginx on Ubuntu

Ajenti is a web based control panel for remote server administration, similar to Webmin or cPanel. It's free and at the time of writing is available for Debian, Ubuntu, RHEL and CentOS, I am using Ubuntu at the moment so this guide will cover installing on Ubuntu using Nginx as a proxy.

Ajenti Install

There are full instructions to install Ajenti on their website, the procedure is to add their repository to your apt-get sources and then install. This is done using the following commands:

$ echo "deb http://repo.ajenti.org/ng/debian main main ubuntu" | sudo tee /etc/apt/sources.list.d/ajenti.list
$ wget http://repo.ajenti.org/debian/key -O- | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install ajenti

I have changed these commands slightly from the ones provided by Ajenti. Firstly I have changed everything to run as a normal user and sudo'd commands that require higher priviledges, second I added the repository to it's own file in sources.list.d instead of appending to sources.list.

Now Ajenti is installed you can access it at https://[your_ip]:8000/, you will need to allow access on port 8000 through your firewall and accept the SSL warning. This is not the most secure way to do this, which is why we are using Nginx as a proxy, but at this stage it is a good test to check the install of Ajenti was successful.

Configure Nginx

The setup for Nginx is really simple, all you have to do is generate a self signed SSL certificate and add a config file for the domain you want to use to access Ajenti.

To generate the SSL certificate use these commands as the root user:

# cd /etc/nginx
# openssl req -new -x509 -nodes -out server.crt -keyout server.key
# chmod 600 server.key

One the certificate files have been generated create this file /etc/nginx/sites-available/ajenti.example.com.conf and add the following content to it:

upstream ajenti  {
    server 127.0.0.1:8000;
}

server {
    server_name ajenti.example.com;
    client_max_body_size 20m;

    listen 80;
    listen [::]:80;
    listen 443 default ssl;

    ssl_certificate      /etc/nginx/server.crt;
    ssl_certificate_key  /etc/nginx/server.key;

    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }

    location / {
        proxy_redirect off;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-NginX-Proxy     true;
        proxy_set_header   Connection        "";
        proxy_http_version 1.1;
        proxy_pass https://ajenti;
    }
}

Restart the Nginx service and update the DNS or your hosts file and Ajenti will be available at ajenti.example.com

If you unblocked port 8000 earlier don't forget to block it again!

References