NGINXTHE WEB SERVER YOU MIGHT ACTUALLY LIKE
ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping
WORKING FORResearchGate gives science back to the people who make it happen.We help researchers build reputation and accel...
GET IN TOUCHstackoverflow:Twitter: @__edorianXing / G+: Volker DuschIRC: edorianMail: php@wallbash.com
LETS GO
WHY ANOTHER WEBSERVER?
WHY NOT LIGHTTPD?
THE BASICSIntroMultiple Servers / DomainsStatic contentSSLError pagesRewritesAuthCachingLoad BalancingProxyPHP!
INTRO/etc/nginx/nginx.conf/etc/nginx/conf.d/*.conf
NGINX CONF BASICSuser nginx;worker_processes 6;worker_cpu_affinity 000001 000010 000100 001000 010000 100000;error_log /va...
NGINX CONFIGURATIONThese dont have to be in the same file. Just "include" .conf files.http {// ...server {// ...location {...
NGINX CONF: BASICShttp {include /etc/nginx/mime.types;default_type application/octet-stream;access_log /var/log/nginx/acce...
SERVERSserver {server_name *.wallbash.com *.wallbash.de;listen 80;// ...}server {server_name _;listen 80;// ...}
STATIC CONTENTlocation / {root /var/www/myApp/html/}
FANCY STATIC CONTENTlocation ~ ^/(js|img|css) {}
DENY ACCESS TO ALL .DOT-FILESlocation ~ /. {access_log off;log_not_found off;deny all;}
SSLserver {server_name _;listen 80;listen 443 ssl;}
SSL - THE WHOLE STORYssl_certificate wildcard.crt;ssl_certificate_key wildcard.key;ssl_session_timeout 5m;ssl_session_cach...
REWRITESserver {server_name http://*;listen 80;rewrite ^ https://$host$request_uri permanent;}
ERROR PAGESerror_page 500 501 502 503 504 /500.html;location /500.html {internal;}location /500 {return 500;}
CACHINGlocation ~ ^/(js|img|css) {expires 14d;}
CACHING - IN MEMCACHE!server {location / {set $memcached_key $uri;memcached_pass name:11211;default_type text/html;error_p...
AUTHlocation / {auth_basic "Restricted";auth_basic_user_file /etc/nginx/conf.d/myApp.htpasswd;}
LOAD BALANCINGupstream web_workers {server www1.example.com;server www2.example.com;server www3.example.com;server www4.ex...
LOAD BALANCING LEGACYupstream web_workers {ip_hash;server www1.example.com;server www2.example.com;server www3.example.com...
PROXYlocation / {proxy_pass http://localhost:8000;proxy_set_header X-Real-IP $remote_addr;proxy_cache zone;}
PHP!
PHP-FPM!?!FastCGI Process Manager
FPM-CONFIG[myApp]listen = 9000;listen.allowed_clients = 127.0.0.1user = phpgroup = phppm = dynamicpm.max_children = 50pm.s...
NGINX + PHPModern frameworkslocation / {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME /var/www/myApp/index.php...
SUPPORTS ANY LAYOUTlocation / {try_files $uri $uri/ /index.php;}
REALLY SUPPORTS ANY LAYOUTMake /foo/ go to .../foo/index.phplocation ~ ^.+.php {fastcgi_index index.php;fastcgi_param SCRI...
SCALING!location / {fastcgi_pass anontherServer:9000;fastcgi_param SCRIPT_FILENAME /var/www/myApp/html/index.php;include f...
THANKS HELGI!@hhttp://helgi.ws/Further reading:https://speakerdeck.com/u/helgi/p/cranking-nginx-to-11-phptek-2012
THANK YOU
Nginx - The webserver you might actually like
Nginx - The webserver you might actually like
Upcoming SlideShare
Loading in …5
×

Nginx - The webserver you might actually like

2,590 views

Published on

IPC Berlin 2013

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,590
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
30
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Nginx - The webserver you might actually like

  1. 1. NGINXTHE WEB SERVER YOU MIGHT ACTUALLY LIKE
  2. 2. ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping
  3. 3. WORKING FORResearchGate gives science back to the people who make it happen.We help researchers build reputation and accelerate scientificprogress.On their terms.
  4. 4. GET IN TOUCHstackoverflow:Twitter: @__edorianXing / G+: Volker DuschIRC: edorianMail: php@wallbash.com
  5. 5. LETS GO
  6. 6. WHY ANOTHER WEBSERVER?
  7. 7. WHY NOT LIGHTTPD?
  8. 8. THE BASICSIntroMultiple Servers / DomainsStatic contentSSLError pagesRewritesAuthCachingLoad BalancingProxyPHP!
  9. 9. INTRO/etc/nginx/nginx.conf/etc/nginx/conf.d/*.conf
  10. 10. NGINX CONF BASICSuser nginx;worker_processes 6;worker_cpu_affinity 000001 000010 000100 001000 010000 100000;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events {worker_connections 1024;}
  11. 11. NGINX CONFIGURATIONThese dont have to be in the same file. Just "include" .conf files.http {// ...server {// ...location {// ...}}}
  12. 12. NGINX CONF: BASICShttp {include /etc/nginx/mime.types;default_type application/octet-stream;access_log /var/log/nginx/access.log main;sendfile on;keepalive_timeout 65;include /etc/nginx/conf.d/*.conf;}
  13. 13. SERVERSserver {server_name *.wallbash.com *.wallbash.de;listen 80;// ...}server {server_name _;listen 80;// ...}
  14. 14. STATIC CONTENTlocation / {root /var/www/myApp/html/}
  15. 15. FANCY STATIC CONTENTlocation ~ ^/(js|img|css) {}
  16. 16. DENY ACCESS TO ALL .DOT-FILESlocation ~ /. {access_log off;log_not_found off;deny all;}
  17. 17. SSLserver {server_name _;listen 80;listen 443 ssl;}
  18. 18. SSL - THE WHOLE STORYssl_certificate wildcard.crt;ssl_certificate_key wildcard.key;ssl_session_timeout 5m;ssl_session_cache shared:SSL:10m;ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers on;ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM;ssl_ecdh_curve secp521r1;
  19. 19. REWRITESserver {server_name http://*;listen 80;rewrite ^ https://$host$request_uri permanent;}
  20. 20. ERROR PAGESerror_page 500 501 502 503 504 /500.html;location /500.html {internal;}location /500 {return 500;}
  21. 21. CACHINGlocation ~ ^/(js|img|css) {expires 14d;}
  22. 22. CACHING - IN MEMCACHE!server {location / {set $memcached_key $uri;memcached_pass name:11211;default_type text/html;error_page 404 @fallback;}}memcached_gzip_flag 2;gunzip on;
  23. 23. AUTHlocation / {auth_basic "Restricted";auth_basic_user_file /etc/nginx/conf.d/myApp.htpasswd;}
  24. 24. LOAD BALANCINGupstream web_workers {server www1.example.com;server www2.example.com;server www3.example.com;server www4.example.com;}
  25. 25. LOAD BALANCING LEGACYupstream web_workers {ip_hash;server www1.example.com;server www2.example.com;server www3.example.com;server www4.example.com;}
  26. 26. PROXYlocation / {proxy_pass http://localhost:8000;proxy_set_header X-Real-IP $remote_addr;proxy_cache zone;}
  27. 27. PHP!
  28. 28. PHP-FPM!?!FastCGI Process Manager
  29. 29. FPM-CONFIG[myApp]listen = 9000;listen.allowed_clients = 127.0.0.1user = phpgroup = phppm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35slowlog = /var/log/php-fpm/myApp-slow.log
  30. 30. NGINX + PHPModern frameworkslocation / {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME /var/www/myApp/index.php;include fastcgi_params;}
  31. 31. SUPPORTS ANY LAYOUTlocation / {try_files $uri $uri/ /index.php;}
  32. 32. REALLY SUPPORTS ANY LAYOUTMake /foo/ go to .../foo/index.phplocation ~ ^.+.php {fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /var/www/myApp/src$fastcgi_script_name;}
  33. 33. SCALING!location / {fastcgi_pass anontherServer:9000;fastcgi_param SCRIPT_FILENAME /var/www/myApp/html/index.php;include fastcgi_params;}
  34. 34. THANKS HELGI!@hhttp://helgi.ws/Further reading:https://speakerdeck.com/u/helgi/p/cranking-nginx-to-11-phptek-2012
  35. 35. THANK YOU

×