Elgg refuses to work on nginx

Hi Folks,

I've been trying to install Elgg on FreeBSD+nginx for a day now, without any success.

During the installation process, it says:

  • We think your server is running the Nginx web server.

    The rewrite rules test failed. You need to configure your web server with Elgg's rewrite rules and try again.

I've tried these, but none worked for me:

 

 This is the most minimal config file that I've been using:

server {
server_name domain.org;
rewrite ^(.*) http://www.domain.org$1 permanent;

# CloudFlare
include /path/to/include/files/cloudflare;
}

server {
listen 80;
server_name www.domain.org;
error_log /path/to/server/vhosts/root/domain.org/log/www_error_log;
access_log /path/to/server/vhosts/root/domain.org/log/www_access_log;

root /path/to/server/vhosts/root/domain.org/www/;
index index.html index.php;
fastcgi_index index.php;

# required for icon direct
rewrite ^\/(.*)\.php\/(.*)[\/]?$ $1.php?$2;

rewrite ^\/action\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1 last;
rewrite ^\/actions\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1 last;

rewrite ^\/export\/([A-Za-z]+)\/([0-9]+)$ services/export/handler.php?view=$1&guid=$2 last;
rewrite ^\/export\/([A-Za-z]+)\/([0-9]+)\/$ services/export/handler.php?view=$1&guid=$2 last;
rewrite ^\/export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ services/export/handler.php?view=$1&guid=$2&type=$3&idname=$4 last;

rewrite ^\/\_css\/css\.css$ _css/css.php last;

rewrite ^\/pg\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/pagehandler.php?handler=$1&page=$2 last;
rewrite ^\/pg\/([A-Za-z0-9\_\-]+)$ engine/handlers/pagehandler.php?handler=$1 last;

rewrite xml-rpc.php engine/handlers/xml-rpc_handler.php last;
rewrite mt/mt-xmlrpc.cgi engine/handlers/xml-rpc_handler.php last;

rewrite ^\/tag/(.*)[\/]?$ engine/handlers/pagehandler.php?handler=search&page=$1 last;

location ~ ^.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /path/to/server/vhosts/root/domain.org/www$fastcgi_script_name;
include fastcgi_params;
}

# Error Pages
include /path/to/include/files/error;

# CloudFlare
include /path/to/include/files/cloudflare;
}

 

Any help will be apperciated.

 

 

  • The wiki was outdated. I've updated it: http://docs.elgg.org/wiki/Elgg_and_nginx

    The 1.8 section is copied from what we're using for this site.

  • hmm.. i just tested the rules that you posted brett.. for me they do not function - i am seeing 404 not found on my local server (nginx 1.4.1-3) when i visit the elgg site.

    i replaced the config lines that i have been successfully using, just to see if maybe yours were better in some way.. the ones i have been using that work ok for me are:

    rewrite ^/pg\/([A-Za-z0-9\_\-]+)$ /engine/handlers/page_handler.php?handler=$1&$args;
    rewrite ^/pg\/([A-Za-z0-9\_\-]+)\/(.*)$ /engine/handlers/page_handler.php?handler=$1&page=$2&$args;
    rewrite ^/tag\/(.+)\/?$ /engine/handlers/page_handler.php?handler=search&page=$1;
    rewrite ^/action\/([A-Za-z0-9\_\-\/]+)$ /engine/handlers/action_handler.php?action=$1&$args;
    rewrite ^/cache\/(.*)$ /engine/handlers/cache_handler.php?request=$1&$args;
    rewrite ^/services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ /engine/handlers/service_handler.php?handler=$1&request=$2&$args;
    rewrite ^/export\/([A-Za-z]+)\/([0-9]+)\/?$ /engine/handlers/export_handler.php?view=$1&guid=$2;
    rewrite ^/export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ /engine/handlers/export_handler.php?view=$1&guid=$2&type=$3&idname=$4;
    rewrite /xml-rpc.php /engine/handlers/xml-rpc_handler.php;
    rewrite /mt/mt-xmlrpc.cgi /engine/handlers/xml-rpc_handler.php;
    rewrite ^/rewrite.php$ /install.php;
    if (!-d $request_filename){
    set $rule_11 1$rule_11;
    }
    if (!-f $request_filename){
    set $rule_11 2$rule_11;
    }
    if ($rule_11 = "21"){
    rewrite ^/([A-Za-z0-9\_\-]+)$ /engine/handlers/page_handler.php?handler=$1;
    }
    if (!-d $request_filename){
    set $rule_12 1$rule_12;
    }
    if (!-f $request_filename){
    set $rule_12 2$rule_12;
    }
    if ($rule_12 = "21"){
    rewrite ^/([A-Za-z0-9\_\-]+)\/(.*)$ /engine/handlers/page_handler.php?handler=$1&page=$2;
    }

  • @Hey Brett are you back? that good! where is Cash, Evan ? i think they are busy?

  • @Brett Thank you so much. You saved the day ;)

  • ah ok, so the glitch is just on my server.. ;)
    i just tested this again and this time the base page did load, but many of the elements such css files did not.. 

  • I use for 1.9.0-dev this rules

    ###
    rewrite cache\/(.*)$ engine/handlers/cache_handler.php?request=$1 last;
    rewrite services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/service_handler.php?handler=$1&request=$2 last;
    rewrite xml-rpc.php engine/handlers/xml-rpc_handler.php last;
    rewrite mt/mt-xmlrpc.cgi engine/handlers/xml-rpc_handler.php last;
    rewrite tag/(.+)/?$ engine/handlers/page_handler.php?handler=search&page=$1 last;

    location / {
    try_files $uri /index.php?__elgg_uri=$uri;
    index index.html index.htm;
    }
    ###

  • Hello, I´m tryin to config Nginx for Elgg but I´m having problems with .css and .js files, the JavaScript console says 404 Not found, so I think is a rewrites configuration issue. Anyone has a working configuration for Elgg that can post for the community?.

    I´ve tested in Debian and now in Centos (with http://centminmod.com/, but without succcess.

  • Well, after three days of testing, my Nginx (Centos)+Elgg 1.8 is working with this config, BUT

    I´ve an issue with /action rewrite, it don´t works, any suggestion??, I've try with:

    rewrite ^/action\/([A-Za-z0-9\_\-\/]+)$ /engine/handlers/action_handler.php?action=$1&$args;

    #rewrite action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1&$args;
    #rewrite action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1 last;
    #rewrite actions\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1 last;
    #rewrite action/login\/([\/A-Za-z0-9_-]+)$ engine/handlers/action_handler.php?action=$1 last;

    I´m very close!!!

     

  • I have a working config, but for 1.9, so you'd need to add few missing rules. Have a look here: https://gist.github.com/Srokap/7dbfc423812f09a5ee43 and for thread with few other versions: https://github.com/Elgg/Elgg/issues/5929