nginx configuration for elgg 1.9

we discussed (on github and in the community) how to configure elgg 1.9 for nginx previously and i did have a working config file here. however, i recently lost the config file while upgrading the local OS and have not been able to locate a working one in the community here or in github.

when i run the one i grabbed from a discussion in github, i just see 'pageok' in the browser window.

from what i can tell this may be related to a domain routing issue, rather than an nginx mis-configuration.. however, so far, i haven't found the cause of the issue.

can anyone point me in a helpful direction to get 1.9rc7 running with nginx?
thanks
 

  • i am still unable to setup an install of 1.9.1 / 1.9.2 here with nginx.

    i see this in the log after the install of 1.9.2, yet no errors that are specific to site pages not loading:

    PHP WARNING: 2014-09-21 21:11:32 (BST): "Argument 4 passed to Elgg_PersistentLoginService::__construct() must be of the type array, null given, called in /var/www/html/dev.1.9.2/engine/classes/Elgg/Di/ServiceProvider.php on line 215 and defined" in file /var/www/html/dev.1.9.2/engine/classes/Elgg/PersistentLoginService.php (line 41)" while reading response header from upstream, client: 127.0.0.1, server: myserver.org, request: "GET /install.php?step=complete HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "myserver..org", referrer: "http://myserver.org/install.php?step=admin"

  • the message i am seeing in firefox when navigating to a page in elgg is:

    The page isn't redirecting properly

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

        This problem can sometimes be caused by disabling or refusing to accept cookies.

  • i ran the apache rewrites through an online apache<>nginx converter and resulted with this:

    location ~ (^\.|/\.) {
        return 403;
    }
    location /cache {
        rewrite ^/cache\/(.*)$ /engine/handlers/cache_handler.php?request=$1&$query_string break;
    }
    location /export {
        rewrite ^/export\/([A-Za-z]+)\/([0-9]+)\/?$ /engine/handlers/export_handler.php?view=$1&guid=$2 break;
        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 break;
    }
    location = /rewrite.php {
        rewrite ^(.*)$ /install.php break;
        }
    location / {
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php?__elgg_uri=$1 break;
            }
    }

    none the less, this did not resolve the problem. i've checked the config several times and still am not detecting the cause of the glitch here. hmm..

  • anyone else got a link for a working 1.9 config for nginx?
    i must be missing something minor/silly..

  • so no update on when the 'official' nginx config file will be available in the docs?

  • We're working through a long backlog of documentation porting, and haven't gotten to it yet. We're always willing to accept pull requests for docs to speed the process along.

  • oh ok sure. i did have a working one, which i deleted somehow accidentally. i'll keep debugging what i have here til i find the cause of the glitches then.

  • Any update on this? I want to upgrade to 1.9 but can't since the nginx 1.8 rewrite rules don't work. Stuck in a loop.

  • This one works for me on my host OS (FC20).  I use php-fpm so you may need to change parts relevant to those.

     

    server {

        listen    80;

        root /path/to/elgg;
        server_name your.elgg.url;

        index index.php index.html index.htm;

        try_files $uri $uri/ =404;
        access_log /path/to/access.log;
        error_log /path/to/error.log;

        location ~ (^\.|/\.) {
            return 403;
        }

        location /cache {
            rewrite ^/cache\/(.*)$ /engine/handlers/cache_handler.php?request=$1&$query_string;
        }

        location /export {
            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;
        }

        location = /rewrite.php {
            rewrite ^(.*)$ /install.php;
        }

        location / {
            try_files $uri $uri/ /index.php?__elgg_uri=$uri&$query_string;
        }


        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            # fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_read_timeout 1200s;
            fastcgi_intercept_errors on;
        }

        # Do not put CSS there or it will break simplecache
        location ~* \.(bmp|js|gif|ico|jpg|jpeg|png)$ {
            expires max;
            # log_not_found off;
        }

        location ~ /\.ht {
            deny all;
        }

        location ~ /\.git {
            deny all;
        }
    }

  • Awesome! This works for now on a fresh new install of Virtualmin using nginx. The codes in bold are what I inserted in nginx.conf

    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;


    events {
        worker_connections  1024;
    }


    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;

        sendfile        on;
        #tcp_nopush     on;

        keepalive_timeout  65;

        #gzip  on;

        include /etc/nginx/conf.d/*.conf;
        server_names_hash_bucket_size 128;
        server {
            server_name yoursite.com www.yoursite.com;
            listen 5.231.43.182;
            root /home/yoursite/public_html;
            index index.html index.htm index.php;
            access_log /var/log/virtualmin/your_access_log;
            error_log /var/log/virtualmin/your_error_log;
            fastcgi_param GATEWAY_INTERFACE CGI/1.1;
            fastcgi_param SERVER_SOFTWARE nginx;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_param SCRIPT_FILENAME /home/yoursite/public_html$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_param REQUEST_URI $request_uri;
            fastcgi_param DOCUMENT_URI $document_uri;
            fastcgi_param DOCUMENT_ROOT /home/yoursite/public_html;
            fastcgi_param SERVER_PROTOCOL $server_protocol;
            fastcgi_param REMOTE_ADDR $remote_addr;
            fastcgi_param REMOTE_PORT $remote_port;
            fastcgi_param SERVER_ADDR $server_addr;
            fastcgi_param SERVER_PORT $server_port;
            fastcgi_param SERVER_NAME $server_name;

            location ~ (^\.|/\.) {
                return 403;
            }

            location /cache {
                rewrite ^/cache\/(.*)$ /engine/handlers/cache_handler.php?request=$1&$query_string;
            }

            location /export {
                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;
            }

            location = /rewrite.php {
                rewrite ^(.*)$ /install.php;
            }

            location / {
                try_files $uri $uri/ /index.php?__elgg_uri=$uri&$query_string;
            }

                # Do not put CSS there or it will break simplecache
            location ~* \.(bmp|js|gif|ico|jpg|jpeg|png)$ {
                expires max;
                # log_not_found off;
            }

            location ~ /\.ht {
                deny all;
            }

            location ~ /\.git {
                deny all;
            }

            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/php-nginx/141332349017611.sock/socket;
            }
        }
    }