FAQ

Page Discussion History

Difference between revisions of "SilverStripe"

(Update the config for SilverStripe)
Line 10: Line 10:
 
<geshi lang="nginx">
 
<geshi lang="nginx">
 
server {
 
server {
    listen       80;
+
listen 80;
    server_name  my-totally-awesome-site.tld;
+
root /path/to/ss/folder;
    root         /PATH/TO/YOUR/SS/ROOT;
+
  
    location / {
+
server_name site.com www.site.com;
        try_files $uri @silverstripe;
+
    }
+
  
    location @silverstripe {
+
location / {
        include fastcgi_params;
+
try_files $uri /framework/main.php?url=$uri&$query_string;
        fastcgi_param SCRIPT_FILENAME $document_root/sapphire/main.php;
+
}
fastcgi_param SCRIPT_NAME /sapphire/main.php;
+
 
        fastcgi_param QUERY_STRING url=$uri&$args;
+
error_page 404 /assets/error-404.html;
        fastcgi_pass 127.0.0.1:9000;
+
error_page 500 /assets/error-500.html;
    }
+
 
 +
location ^~ /assets/ {
 +
sendfile on;
 +
try_files $uri =404;
 +
}
 +
 
 +
location ~ /framework/.*(main|rpc|tiny_mce_gzip)\.php$ {
 +
fastcgi_keep_conn on;
 +
fastcgi_pass  127.0.0.1:9000;
 +
fastcgi_index  index.php;
 +
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 +
include        fastcgi_params;
 +
}
 +
 
 +
location ~ /(mysite|framework|cms)/.*\.(php|php3|php4|php5|phtml|inc)$ {
 +
deny all;
 +
}
 +
 
 +
location ~ /\.. {
 +
deny all;
 +
}
 +
 
 +
location ~ \.ss$ {
 +
satisfy any;
 +
allow 127.0.0.1;
 +
deny all;
 +
}
 +
 
 +
location ~ web\.config$ {
 +
deny all;
 +
}
 +
 
 +
location ~ \.ya?ml$ {
 +
deny all;
 +
}
 +
 
 +
location ^~ /vendor/ {
 +
deny all;
 +
}
 +
 
 +
location ~* /silverstripe-cache/ {
 +
deny all;
 +
}
 +
 
 +
location ~* composer\.(json|lock)$ {
 +
deny all;
 +
}
 +
 
 +
location ~* /(cms|framework)/silverstripe_version$ {
 +
deny all;
 +
}
 +
 
 +
location ~ \.php$ {
 +
                fastcgi_keep_conn on;
 +
                fastcgi_pass   127.0.0.1:9000;
 +
                fastcgi_index  index.php;
 +
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
 +
                include        fastcgi_params;
 +
}
 
}
 
}
 
</geshi>
 
</geshi>
  
This has been tested with SS 2.3 and 2.4.
+
This has been tested with SS 3.1.

Revision as of 09:51, 10 March 2014

SilverStripe is a modern PHP based CMS Framework that runs happily on nginx. There are several built in failsafes that will attempt to rectify any errors in rewrite rules. First, SS relies on an .htaccess file to define how to handle URLs. Second, in the event that rewriting has failed the index.php file will attempt to set internal variables and include the core /sapphire/main.php file for processing.

These instructions assume you are using PHP configured as Fast CGI or PHP-FPM listening on 127.0.0.1:9000. Make any appropriate changes fastcgi_params as needed for your environment.

The basic rewrite that controls all SilverStripe calls involve passing the URI and any GET vars to $document_root/sapphire/main.php.

  1. Remove the .htaccess file and index.php in the root of your SilverStripe installation (Just to be sure)
  2. Apply a config similar to the following:
server {
	listen 80;
	root /path/to/ss/folder;
 
	server_name site.com www.site.com;
 
	location / {
		try_files $uri /framework/main.php?url=$uri&$query_string;
	}
 
	error_page 404 /assets/error-404.html;
	error_page 500 /assets/error-500.html;
 
	location ^~ /assets/ {
		sendfile on;
		try_files $uri =404;
	}
 
	location ~ /framework/.*(main|rpc|tiny_mce_gzip)\.php$ {
		fastcgi_keep_conn on;
		fastcgi_pass   127.0.0.1:9000;
		fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include        fastcgi_params;
	}
 
	location ~ /(mysite|framework|cms)/.*\.(php|php3|php4|php5|phtml|inc)$ {
		deny all;
	}
 
	location ~ /\.. {
		deny all;
	}
 
	location ~ \.ss$ {
		satisfy any;
		allow 127.0.0.1;
		deny all;
	}
 
	location ~ web\.config$ {
		deny all;
	}
 
	location ~ \.ya?ml$ {
		deny all;
	}
 
	location ^~ /vendor/ {
		deny all;
	}
 
	location ~* /silverstripe-cache/ {
		deny all;
	}
 
	location ~* composer\.(json|lock)$ {
		deny all;
	}
 
	location ~* /(cms|framework)/silverstripe_version$ {
		deny all;
	}
 
	location ~ \.php$ {
                fastcgi_keep_conn on;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
	}
}

This has been tested with SS 3.1.