Upgrade to Pro — share decks privately, control downloads, hide ads and more …

nginx for SilverStripe

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

nginx for SilverStripe

Why and how you should be using nginx for your SilverStripe sites — SilverStripe Europe 2014

Philipp Krenn

October 03, 2014

Transcript

64 slides
  1. there's this russian server nginx. all the porn sites use

    it. it must be decent. 1 Jonathan Vanasco, http://www.destructuring.net/2006/10/09/nginx/
  2. I only believe in statistics that I doctored myself. (Winston

    Churchill) http://w3techs.com/technologies/ cross/web_server/ranking
  3. nginx does those six things, and it does five of

    them 50 times faster than Apache. 1 Chris Lea, http://maisonbisson.com/post/12249/chris- lea-on-nginx-and-wordpress/
  4. Apache Thread / process-oriented Spawn a process for each connection

    (1MB+ RAM) Apache 2.4 multi-process mode reduces memory usage
  5. Problem 200KB response Milliseconds to generate or retrieve 10s to

    transmit at 160kbps (20KB/s) 1000 connections :(
  6. Event-driven Single nonblocking thread (one process per core) — node.js,

    Redis,... Stable memory usage, no context switches
  7. Event-driven Receive request, trigger events in a process Process handles

    events, returns output http://en.wikipedia.org/wiki/Reactor_pattern
  8. Base nginx http { include mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log;

    error_log /var/log/nginx/error.log debug; sendfile on; keepalive_timeout 65; gzip on;
  9. SilverStripe projects server { root /Users/philipp/Sites/silverstripe-30; server_name silverstripe-30.local; include _silverstripe3;

    } server { root /Users/philipp/Sites/silverstripe-31; server_name silverstripe-31.local; include _silverstripe3; }
  10. _silverstripe3 error_page 404 /assets/error-404.html; error_page 500 /assets/error-500.html; location ~* ^.+.(htm|html|jpg|jpeg|gif|png|svg|ico|css|

    zip|tgz|gz|rar|bz2|doc|docx|xls|xlsx|pdf| ppt|pptx|txt|tar|mid|midi|wav|bmp|rtf|js)$ { access_log off; expires max; }
  11. _silverstripe3 location ~* \.php$ { fastcgi_keep_conn on; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass

    unix:/var/run/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_read_timeout 120; fastcgi_connect_timeout 60; fastcgi_send_timeout 120; fastcgi_buffer_size 64k; fastcgi_buffers 4 65k; fastcgi_busy_buffers_size 128k; }
  12. _silverstripe3 location / { try_files $uri @silverstripe; } location @silverstripe

    { fastcgi_keep_conn on; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_read_timeout 120; fastcgi_connect_timeout 60; fastcgi_send_timeout 120; fastcgi_buffer_size 64k; fastcgi_buffers 4 65k; fastcgi_busy_buffers_size 128k; fastcgi_param SCRIPT_FILENAME $document_root/framework/main.php; fastcgi_param SCRIPT_NAME /framework/main.php; fastcgi_param QUERY_STRING url=$uri&$args; }
  13. _silverstripe3 # CMS & Framework .htaccess rules location ~ ^/(cms|framework|mysite)/.*\.(php|php[345]|phtml|inc)$

    { deny all; } location ~ ^/(cms|framework)/silverstripe_version$ { deny all; } location ~ ^/framework/.*(main|static-main|rpc|tiny_mce_gzip)\.php$ { allow all; }
  14. _silverstripe3 # Don't execute scripts in the assets folder location

    ^~ /assets/ { sendfile on; try_files $uri $uri/ =404; } location ~ ^/silverstripe-cache { deny all; } location ~ ^/logs { deny all; }
  15. _silverstripe3 location ~ ^/(vendor|composer.json|composer.lock) { deny all; } location ~

    \.yml$ { deny all; } location ~ \.ss$ { satisfy any; allow 127.0.0.1; deny all; } location ~ /\. { deny all; }
  16. http://wiki.dreamhost.com/ Web_Server_Performance_Comparison 25,000 requests, 5KB PNG $ ab -n 25000

    -c 50 http://example.com/ logo.png Concurrency 50, 100, 500, 1000, 1500, 2000, 2500, 3000
  17. Solution? Is this your bottleneck? Could you configure Apache to

    be fast (enough)? Is PHP-FPM the solution?

More Decks by Philipp Krenn

Other Decks in Programming