Nginx The webserver you might actually like
description
Transcript of Nginx The webserver you might actually like
![Page 1: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/1.jpg)
NGINXTHE WEB SERVER YOU MIGHT ACTUALLY LIKE
![Page 2: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/2.jpg)
ABOUT MEPHP since 10 yearsCICleanCodeDevOpsTDDShipping
![Page 3: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/3.jpg)
![Page 4: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/4.jpg)
GET IN TOUCH
stackoverflow: Twitter: @__edorianXing / G+: Volker DuschIRC: edorianMail: [email protected]
![Page 5: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/5.jpg)
LET'S GO
![Page 6: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/6.jpg)
WHY ANOTHER WEBSERVER?
![Page 7: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/7.jpg)
WHY NOT LIGHTTPD?
![Page 8: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/8.jpg)
THE BASICSIntroMultiple Servers / DomainsStatic contentSSLError pagesRewritesAuthCachingLoad BalancingProxyPHP!
![Page 9: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/9.jpg)
INTRO/etc/nginx/nginx.conf/etc/nginx/conf.d/*.conf
![Page 10: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/11.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/12.jpg)
SERVERSserver { server_name *.wallbash.com *.wallbash.de; listen 80; // ...}
server { server_name _; listen 80; // ...}
![Page 13: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/13.jpg)
STATIC CONTENTlocation / { root /var/www/myApp/html/}
![Page 14: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/14.jpg)
FANCY STATIC CONTENTlocation ~ ̂\/(js|img|css) {}
![Page 15: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/15.jpg)
DENY ACCESS TO ALL .DOT-FILESlocation ~ /\. { access_log off; log_not_found off; deny all;}
![Page 16: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/16.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/17.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/18.jpg)
REWRITESserver { server_name http://*; listen 80; rewrite ̂ https://$host$request_uri permanent;}
![Page 19: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/19.jpg)
CACHINGlocation ~ ̂\/(js|img|css) { expires 14d;}
![Page 20: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/20.jpg)
AUTHlocation / { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/conf.d/myApp.htpasswd;}
![Page 21: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/21.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/22.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/23.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/24.jpg)
PHP!
![Page 25: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/25.jpg)
PHP-FPM!?!FastCGI Process Manager
![Page 26: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/26.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/27.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/28.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/29.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/30.jpg)
THANK YOU
![Page 31: Nginx The webserver you might actually like](https://reader033.fdocuments.us/reader033/viewer/2022051514/549c4c28ac7959d82a8b46c5/html5/thumbnails/31.jpg)