Configuring Status.Net for NGINX in a Subdirectory

This morning I tried to get status.net to work from a subdirectory of my main site, a task which proved to be quite frustrating, especially for someone who’s not too great at rewrite rules in apache, let alone NGINX. Unfortunately, there is also not much documentation on this topic online since status.net does not officially support NGINX. That’s okay though. I don’t know much about rewrites, since they use regex, it seems you should be able to make just about anything work (I could be wrong about that though).

To get this to work, we first need a location directive for our main site. That would look something like

location / {
        index index.php;
        try_files   $uri $uri/ @rewriteSection;
}
location @rewriteSection {
        rewrite (.*blah.*) index.php?q=$1;
}

Now that we have that, we can go ahead and put our subdirectory directive in here. For the purposes of this demonstration, our status.net instance will be running in a directory called testsub.

location /testsub {
        index index.php;
        try_files   $uri $uri/ @testsub;
}
location @testsub {
        ## FOR FANCY URLS FALSE
        ## rewrite ^/testsub/index.php/(.*)$ /testsub/index.php?p=$1 last;
        ## FOR FANCY URLS TRUE
        rewrite ^/testsub/(.*)$ /testsub/index.php?p=$1 last;
}

To make this work for your instance, all you should need to do is swap out the testsub directory references for the directory your status.net instance is running in and you should be set. Keep in mind though that by default, status.net has fancy URLs disabled. That means you’ll have to use the first rewrite line. If fancy URLs are turned on, then you should use the second rewrite line. That should be it!

Yay microblogging!

Category:Nginx Category:Status.Net Category:Blogging