Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
2k
360° Monitoring of Your Microservices
xeraa
7
3.3k
Scale Your Metrics with Elasticsearch
xeraa
4
130
YAML Considered Harmful
xeraa
0
2k
Scale Your Elasticsearch Cluster
xeraa
1
280
Hands-On ModSecurity and Logging
xeraa
2
140
Centralized Logging Patterns
xeraa
1
980
Dashboards for Your Management with Kibana Canvas
xeraa
1
450
Make Your Data FABulous
xeraa
3
810
Other Decks in Programming
See All in Programming
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
600
Remix on Hono on Cloudflare Workers
yusukebe
1
390
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
7.2k
Missing parts when designing and implementing Android UI
ericksli
0
370
PaaSとSaaSの境目で信頼性と開発速度を両立する 〜TROCCO®︎のこれまでとこれから〜
gtnao
5
5.8k
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
720
AWS AppSyncを用いた GraphQL APIの開発について - NIFTY Tech Talk #22
niftycorp
PRO
0
110
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
150
5分ぐらいで分かる、トリミング機能の作り方
tsutsuitakumi
0
160
as(型アサーション)を書く前にできること
marokanatani
10
3k
Vapor Revolution
kazupon
2
2.4k
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
190
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
327
38k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Building Adaptive Systems
keathley
38
2.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Docker and Python
trallard
40
3.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Code Reviewing Like a Champion
maltzj
520
39k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
We Have a Design System, Now What?
morganepeng
50
7.2k
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