Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
nginx for SilverStripe
Search
Philipp Krenn
October 03, 2014
Programming
1
3.3k
nginx for SilverStripe
Why and how you should be using nginx for your SilverStripe sites — SilverStripe Europe 2014
Philipp Krenn
October 03, 2014
Tweet
Share
More Decks by Philipp Krenn
See All by Philipp Krenn
Full-Text Search Explained
xeraa
11
2.2k
360° Monitoring of Your Microservices
xeraa
7
3.4k
Scale Your Metrics with Elasticsearch
xeraa
4
140
YAML Considered Harmful
xeraa
0
2.1k
Scale Your Elasticsearch Cluster
xeraa
1
310
Hands-On ModSecurity and Logging
xeraa
2
190
Centralized Logging Patterns
xeraa
1
1.1k
Dashboards for Your Management with Kibana Canvas
xeraa
1
470
Make Your Data FABulous
xeraa
3
890
Other Decks in Programming
See All in Programming
エンジニア向け採用ピッチ資料
inusan
0
150
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
970
Select API from Kotlin Coroutine
jmatsu
1
190
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
220
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
100
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
110
関数型まつりレポート for JuliaTokai #22
antimon2
0
140
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
830
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
370
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
170
C++20 射影変換
faithandbrave
0
500
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
134
9.3k
GitHub's CSS Performance
jonrohan
1031
460k
Automating Front-end Workflow
addyosmani
1370
200k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Building an army of robots
kneath
306
45k
Facilitating Awesome Meetings
lara
54
6.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Writing Fast Ruby
sferik
628
61k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.4k
Transcript
Philipp Krenn, @xeraa
GSoC student 2007 Book 2011 GSoC mentor 2012 SilverStripe Austria
meetup
Why?
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/
Subversion vs Git
I only believe in statistics that I doctored myself. (Winston
Churchill) http://w3techs.com/technologies/ cross/web_server/ranking
None
Apache is like Microsoft Word, it has a million options
but you only need six.
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/
What?
Public launch in 2004 by Igor Sysoev http://www.rambler.ru BSD licensed
(two-clause)
Stable 1.6.2, Preview 1.7.6 C, cross-platform Commercial support from Nginx
Inc.
Features Load balancer Reverse proxy TLS/SSL (SNI), SPDY,... support
Users WordPress.com app server + load balancer Static content on
GitHub SSL termination Wikipedia
nginx is a lightweight event-driven reverse proxy for web and
mail services. 1 http://nginx.org
Great! But...
...it doesn't work the Apache way For example .htaccess
Performance For every request, check every directory, read and parse
every file Changes effective immediately
Example http://example.com/assets/Uploads/ gallery/image.jpg
None
Apache Thread / process-oriented Spawn a process for each connection
(1MB+ RAM) Apache 2.4 multi-process mode reduces memory usage
Problem 200KB response Milliseconds to generate or retrieve 10s to
transmit at 160kbps (20KB/s) 1000 connections :(
it's time for web servers to handle ten thousand clients
simultaneously 1 Daniel Kegel
C10K challenge nginx solution: Event- driven architecture
Event-driven Single nonblocking thread (one process per core) — node.js,
Redis,... Stable memory usage, no context switches
Event-driven Receive request, trigger events in a process Process handles
events, returns output http://en.wikipedia.org/wiki/Reactor_pattern
http://www.aosabook.org/en/nginx.html#fig.nginx.arch
However... PHP is blocking node.js isn't — similar to nginx
Details "The Architecture of Open Source Applications" http://www.aosabook.org/en/ nginx.html
PHP-FPM FastCGI Process Manager, included in PHP 5.3.3+ Standalone process
like MySQL, Memcached,...
How?
Install (Ubuntu) $ sudo apt-get update && sudo apt-get install
nginx php5-fpm -y
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;
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; }
_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; }
_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; }
_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; }
_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; }
_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; }
_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; }
Show me some benchmarks
None
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
None
None
Benchmark your projects Build Benchmark Repeat
Solution? Is this your bottleneck? Could you configure Apache to
be fast (enough)? Is PHP-FPM the solution?
Nevertheless...
None
Questions?
PS: PHP Secure Configuration Checker
https://github.com/sektioneins/pcc SektionEins (Suhoshin) PHP 5.4+ BSD license
Security checks Critical: Fix this NOW Example: Register globals
Security checks High: You should really look at this Example:
Allow URL fopen
Security checks Medium: This might be a problem Example: Display
errors on
Security Checks Low: Boring stuff Example: Execution time > 300s
Security checks Maybe: Not sure, check manually Example: Memory limit
> 128MB
Security checks Comment: Just mentioning it Example: Upload max filesize
is the default (8MB)
Modes CLI Web
Web security 127.0.0.1 mtime < 2d
How good / bad are the Ubuntu 14.04 defaults? nginx
+ PHP-FPM
None
Give it a try https://github.com/xeraa/ppc-test Vagrant — more tomorrow
Conclusion: Simple but gets the job done