Codeigniter in subdirectory on Nginx 404

Got it working, the solution was to use $request_filename; instead of $document_root$fastcgi_script_name;

location /api/ {
    alias  /var/www/api/;
    try_files $uri $uri/ /api/index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index   index.php;
        fastcgi_pass    backend;
        include /etc/nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME $request_filename;
    }
}