Configure an Agavi Site with NGINX (using PHP-FPM)

I was used to configure my Agavi site with Lighttpd and recently switched to Nginx. The setup for Nginx was not so common to me, so I decided to write down what I had to do to configure it properly. Here is an example for dracoblue.net. Please change the parts of the script to suit your needs (the necessary parts are highlighted with "HINT:").

First of all install php5-fpm. On ubuntu I did it this way:

$ sudo apt-get install php5-fpm

Now create a new file:

$ vim /etc/nginx/sites-enabled/dracoblue.net

And add the following:

server {
    listen dracoblue.net:80;
    # HINT: Add the servername, so Agavi is able to see that it's dracoblue.net
    # Otherwise you'll get something like "localhost" here
    server_name dracoblue.net;

    location / {
        # HINT: The directory where index.php is
        root   /home/dracobluenet/tags/1.0.0/pub;
        index index.php;

        # HINT: All files except those in "static" should be served by index.php
        location ~* ^/(favicon.ico|robots.txt|static) {

        # HINT: All files except those in "static" should be served by index.php
        if ($uri !~ "^/(favicon.ico|robots.txt|static|index.php)") {
            rewrite ^/([^?]*)$ /index.php?/$1 last;

    location ~ \.php($|/) {
        include /etc/nginx/fastcgi_params;
        # HINT: The directory where index.php is + $fastcgi_script_name
        fastcgi_param SCRIPT_FILENAME /home/dracobluenet/tags/1.0.0/pub$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;

As you can see, for projects I usually have only a "static" folder which is not served by agavi. This keeps the amount of work low, which nginx needs to do for each request to decide whether it should be served by php or not. I also added robots.txt and favicon.ico since you usually have them in root, too.

Restart nginx.

$ /etc/init.d/nginx restart
In agavi, articles, lighttpd, linux, nginx, php by
@ 09 Dec 2010, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files