Skip to content

Instantly share code, notes, and snippets.

@chtombleson
Created January 30, 2014 07:04
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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;
}
}
@chtombleson
Copy link
Author

If your having problems with 502 bad gateway errors try these settings in the @silverstripe location block

fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
proxy_connect_timeout 90;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_intercept_errors on;

@gordonbanderson
Copy link

hi Chris

I tried this config out whilst it is mostly working I run into an issue with editing pages. When I open /admin/pages and then click on any random page other than the current one the page does not load. I dont appear to be able to copy and paste the response but it is returning PHP code, not the result of execution of that code. I added X-Trace headers and can confirm that the request went through the @silverstripe section of the config.

Any ideas?

Cheers

Gordon

@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