nginx the webserver you might actually like

31
NGINX THE WEB SERVER YOU MIGHT ACTUALLY LIKE

Upload: edorian

Post on 25-Dec-2014

1.334 views

Category:

Education


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Nginx   The webserver you might actually like

NGINXTHE WEB SERVER YOU MIGHT ACTUALLY LIKE

Page 2: Nginx   The webserver you might actually like

ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping

Page 3: Nginx   The webserver you might actually like
Page 4: Nginx   The webserver you might actually like

GET IN TOUCH

stackoverflow: Twitter: @__edorianXing / G+: Volker DuschIRC: edorianMail: [email protected]

Page 5: Nginx   The webserver you might actually like

LET'S GO

Page 6: Nginx   The webserver you might actually like

WHY ANOTHER WEBSERVER?

Page 7: Nginx   The webserver you might actually like

WHY NOT LIGHTTPD?

Page 8: Nginx   The webserver you might actually like

THE BASICSIntroMultiple Servers / DomainsStatic contentSSLError pagesRewritesAuthCachingLoad BalancingProxyPHP!

Page 9: Nginx   The webserver you might actually like

INTRO/etc/nginx/nginx.conf/etc/nginx/conf.d/*.conf

Page 10: Nginx   The webserver you might actually like

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;}

Page 11: Nginx   The webserver you might actually like

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;}

Page 12: Nginx   The webserver you might actually like

SERVERSserver { server_name *.wallbash.com *.wallbash.de; listen 80; // ...}

server { server_name _; listen 80; // ...}

Page 13: Nginx   The webserver you might actually like

STATIC CONTENTlocation / { root /var/www/myApp/html/}

Page 14: Nginx   The webserver you might actually like

FANCY STATIC CONTENTlocation ~ ̂\/(js|img|css) {}

Page 15: Nginx   The webserver you might actually like

DENY ACCESS TO ALL .DOT-FILESlocation ~ /\. { access_log off; log_not_found off; deny all;}

Page 16: Nginx   The webserver you might actually like

SSLssl_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;

Page 17: Nginx   The webserver you might actually like

ERROR PAGESerror_page 500 501 502 503 504 /500.html;

location /500.html { internal;}

location /500 { return 500;}

Page 18: Nginx   The webserver you might actually like

REWRITESserver { server_name http://*; listen 80; rewrite ̂ https://$host$request_uri permanent;}

Page 19: Nginx   The webserver you might actually like

CACHINGlocation ~ ̂\/(js|img|css) { expires 14d;}

Page 20: Nginx   The webserver you might actually like

AUTHlocation / { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/conf.d/myApp.htpasswd;}

Page 21: Nginx   The webserver you might actually like

LOAD BALANCINGupstream web_workers { server www1.example.com; server www2.example.com; server www3.example.com; server www4.example.com;}

Page 22: Nginx   The webserver you might actually like

LOAD BALANCING LEGACYupstream web_workers { ip_hash; server www1.example.com; server www2.example.com; server www3.example.com; server www4.example.com;}

Page 23: Nginx   The webserver you might actually like

PROXYlocation / { proxy_pass http://localhost:8000; proxy_set_header X-Real-IP $remote_addr; proxy_cache zone;}

Page 24: Nginx   The webserver you might actually like

PHP!

Page 25: Nginx   The webserver you might actually like

PHP-FPM!?!FastCGI Process Manager

Page 26: Nginx   The webserver you might actually like

FPM-CONFIG[myApp]

listen = 9000

;listen.allowed_clients = 127.0.0.1

user = phpgroup = php

pm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/myApp-slow.log

Page 27: Nginx   The webserver you might actually like

NGINX + PHPlocation / { fastcgi_pass 127.0.01.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/myApp/html/index.php; include fastcgi_params;}

Page 28: Nginx   The webserver you might actually like

SCALING!location / { fastcgi_pass anontherServer:9000; fastcgi_param SCRIPT_FILENAME /var/www/myApp/html/index.php; include fastcgi_params;}

Page 29: Nginx   The webserver you might actually like

THANKS HELGI!@hhttp://helgi.ws/Further reading:https://speakerdeck.com/u/helgi/p/cranking-nginx-to-11-phptek-2012

Page 30: Nginx   The webserver you might actually like

THANK YOU

Page 31: Nginx   The webserver you might actually like