Search code examples
configurationurl-rewritingnginxconcrete5

Deploying concrete5 on nginx


I have a concrete5 site that works 'out of the box' in apache server. However I am having a lot of trouble running it in nginx.

The following is the nginx configuration i am using:

server {
    root /home/test/public;
    index index.php;

    access_log /home/test/logs/access.log;
    error_log /home/test/logs/error.log;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ index.php;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
    # pass the PHP scripts to FastCGI server listening on unix socket
    #
    location ~ \.php($|/) {
            fastcgi_pass unix:/tmp/phpfpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            include fastcgi_params;
    }
    location ~ /\.ht {
            deny  all;
    }
}

I am able to get the homepage but am having problem with the inner pages. The inner pages display an "Access denied". Possibly the rewrite is not working, in effect I think its querying and trying to execute php files directly instead of going through the concrete dispatcher.

I am totally lost here.

Thankyou for your help, in advance.


Solution

  • Changed the configurations to:

    server {
        root /home/test/public;
        index index.php;
    
        access_log /home/test/logs/access.log;
        error_log /home/test/logs/error.log;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.php/$request_uri;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
    
        # pass the PHP scripts to FastCGI server listening on unix socket
        #
        location ~ \.php($|/) {
                set $script $uri;
                if ($uri ~ "^(.+\.php)(/.+)") {
                        set $script $1;
                }
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$script;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/tmp/phpfpm.sock;
        }
    
        location ~ /\.ht {
                deny  all;
        }
    }
    

    And it works thanks to hangover and the link he provided in serverfault.

    I am still not clear what I did wrong, maybe an nginx expert can help me understand.