Skip to content

Instantly share code, notes, and snippets.

@chtombleson
Created January 30, 2014 07:04
Show Gist options
  • Save chtombleson/8703899 to your computer and use it in GitHub Desktop.
Save chtombleson/8703899 to your computer and use it in GitHub Desktop.
Silverstripe nginx config
server {
listen 80;
server_name example.com;
root /var/www/example.com;
error_log /var/log/example.com/error.log;
access_log /var/log/example.com/access.log;
location / {
try_files $uri @silverstripe;
}
location ~ ^/(index|install).php {
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# whitelist php files that are called directly and need to be interpreted
location = /framework/thirdparty/tinymce/tiny_mce_gzip.php {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location = /framework/thirdparty/tinymce-spellchecker/rpc.php {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location @silverstripe {
expires off;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/framework/main.php;
fastcgi_param SCRIPT_NAME /framework/main.php;
fastcgi_param QUERY_STRING url=$uri&$args;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 64k;
}
#
# Error Pages
#
error_page 503 @maintenance;
if (-f $document_root/maintenance.html ) {
return 503;
}
location @maintenance {
try_files /maintenance.html =503;
}
error_page 500 /assets/error-500.html;
#
# Deny access to protected folder/files
#
location ^~ /assets/ {
try_files $uri =404;
}
location ^~ /silverstripe-cache/ {
deny all;
}
location ^~ /vendor/ {
deny all;
}
location ~ /composer\.(json|lock) {
deny all;
}
location ~ /(\.|web\.config) {
deny all;
}
location ~ \.(yml|bak|swp)$ {
deny all;
}
location ~ ~$ {
deny all;
}
location ~ \.(php|php[345]|phtml|inc)$ {
deny all;
}
location ~ ^/(cms|framework)/silverstripe_version$ {
deny all;
}
}
@gordonbanderson
Copy link

Oh it seems a lot of the AJAX is broken. At least that gives me a another avenue to investigate this issue :)

@gordonbanderson
Copy link

I've now resolved this issue thanks to simon_w on IRC. I had one PHP file which started with <? instead of <?php - I fixed this and lo and behold nginx working again :) As such disregard above query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment