- ãªãã·ã§ã³1ïŒ éå»6ãæéã«æãå±ããªãã£ãéšåãç· ããŸãã 誰ããããªããç解ããçšèªãä»ã®ã¿ã¹ã¯ã«ç§»åããŸãã ãµã€ããæ³å€ãªè² è·ããæãããã«ãã¹ãŒããŒãã³ãã ãã®åœ¹å²ãæããããç¡æãã§åé¡ã解決ããŸãïŒæ©åšãžã®è¿œå ã®æ³šå
¥ãªãïŒã èšäºãTuning nginxãã圹ç«ã€ãããããŸãã ã
- 解決ç2ïŒ æè¡ããŒã¹ãæ¹åããïŒãµãŒããŒã§é è³ã賌å
¥ãããã£ã¹ã¯ã·ã¹ãã ãæ¹åããããŒã¿ããŒã¹ã®äžã«å¥ã®ãµãŒããŒãé
眮ããïŒã ååãšããŠãåé¡ã¯è§£æ±ºãããŠããããããã延æãããŠããŸãã ããã§ããæã蟌ã¿ããè² è·ã®æµå
¥ã®ç¬¬2æ³¢ã«åããæéãã§ããŸãããè² è·ã¯å€§ãããªãããã匷åã«ã«ããŒãããŸãã
- 解決ç3ïŒ ããªãã®ãªãã·ã§ã³ãããããã³ã¡ã³ãããåŠã³ãŸãã
ä»çµã¿
ãµã€ãã¯åžžã«è€æ°ã®ç¬ç«ãããããã¯ã«åå²ããããšãã§ãããã®çæã¯ïŒå¿ èŠã«å¿ããŠïŒç°ãªããµãŒããŒã§å®è¡ã§ããŸãã
åæã«ãç¹å®ã®ãã³ã¬ã¯ã¿ãŒãããããã¯ãåäžã®å šäœã«ã¢ã»ã³ãã«ããŸããå²ãåœãŠãããæéå ã«äœããã®çç±ã§ãããã¯ãäœæãããªãã£ãå Žåãããã¯ã¯ã©ã€ã¢ã³ãã«ãã²ãŒããŠã§ã€ã¿ã€ã ã¢ãŠãããŸãã¯ãå éšãµãŒããŒãšã©ãŒããäžããçç±ã«ã¯ãªããŸããã æ£åžžã«äœæããããããã¯ãåéããã倱æãã®ãµã€ãã§ãã£ãã·ã¥ããå€ãã³ã³ãã³ãã衚瀺ã§ããŸãã
ãã®ãããªã¢ãã«ãå®è£ ããã«ã¯ãWebéçºãã¯ãããžãŒã®ããã©ã³ã§ããssiãå¿ èŠã§ãã ãã³ã¬ã¯ã¿ãŒããšããŠãèšäºã®ã¿ã€ãã«ããæãããªããã«ã nginxãæ©èœããŸãã fastcgi_cacheã¢ãžã¥ãŒã«ã®ãããã§ãå¥è·¡ããå¯èœã«ãªããŸãã
ããã§ã¯ãè¡ããŸãããïŒ
äœåãªãªã³ã¯ãé€å€ããŸã
Apacheã¯å¿ èŠãããŸãããApacheã®ååšã¯ãååãšããŠRewriteRulesã®äœ¿çšã«ãã£ãŠèª¬æãããŸãã nginxã«ã¯ãmod_rewriteã®é¡äŒŒç©ããŸãã¯æ£èŠè¡šçŸã䜿çšããå Žæ/ãšã€ãªã¢ã¹ã®çµã¿åããããã ããã®æ©èœã«ãããApacheã®RewriteRuleã«é¡äŒŒç©ãæžã蟌ãããšãã§ããŸãã ããã«ãææ°ã®ãã¬ãŒã ã¯ãŒã¯ã§ã¯ããšã³ãžã³èªäœãå ¥åURLã解æã§ããŸãïŒããšãã°ã Zend Frameworkã® Zend_Controller_Router_Rewrite ïŒ
fastcgiããã¯ãšã³ããšããŠãä»»æã®ãã©ãããã©ãŒã ã䜿çšã§ããŸãã äŸã¯phpã«ãããŸãããããã¯Pythonãperlã§åæ§ã®ã³ãŒããæžãããšãã§ããªããšããæå³ã§ã¯ãããŸããã
fastcgiã¢ãŒãã§phpãå®è¡ããŸãã
# /bin/su -m www_user -c "PHP_FCGI_CHILDREN=8 /usr/bin/php-cgi -q -b 127.0.0.1:7777 &"
php.iniïŒerror_log = /var/log/fastcgi/fastcgi.logïŒã§ãã°ãã¡ã€ã«ãžã®ãã¹ãæå®ããããšãã§ããŸãããphp-cgiãåèµ·åããå¿ èŠããããŸãã
ç§ãã¡ã¯ããïŒ
# killall php-cgi
ãã¹ãŠãæ°ããæ¹æ³ã§éå§ããŸã
fastcgiãéå§ããããé«åºŠãªæ¹æ³ã¯ã php- fpmãã€ã³ã¹ããŒã«ããããšã§ãã
nginxãã€ã³ã¹ããŒã«ãã
ãªããžããª/ããŒãããæšæºãèšå®ã§ããŸã...ãããããã£ãã·ã¥å ã®ãã¡ã€ã«ããã¯ãªãŒã³ãã«åäœãããã«ã¯ãã³ã³ãã€ã«ããå¿ èŠããããŸãã
ã¢ãžã¥ãŒã«ãå¿ èŠã§ãïŒ ngx_cache_purge
redhatã®ãããªã·ã¹ãã ã§ãããã©ã®ããã«è¡ãããšãã§ãããã詳现ã«èª¬æããé¡æšã«ããã·ã¹ãã çšã«ã³ã³ãã€ã«ããŸãã
ïŒcdã/ rpmbuild / SRPMS ïŒyumdownloader --source nginx ïŒrpm -ivh nginx-0.7.65-1.fc12.src.rpm
./configureãªã¹ãã®ã©ããã«ããnginx.specãã¡ã€ã«ãç·šéãã--add -module = / root / rpmbuild / BUILD / ngx_cache_purge-1.0 \ãšããè¡ãæ¿å ¥ããŸã ã äžèŠãªã¢ãžã¥ãŒã«ãå«ãè¡ãããã«åé€ã§ããŸãïŒããšãã°ã-with-ipv6 \ã-with-http_dav_module \ã-with-mail \ã-with-mail_ssl_module \ ...ïŒ
http://labs.frickle.com/files/ngx_cache_purge-1.0.tar.gzã®å 容ããã©ã«ããŒ/root/rpmbuild/BUILD/ngx_cache_purge-1.0ã«è§£åããŸãã
ãã¹ãŠãã³ã³ãã€ã«ã§ããŸãïŒ
ïŒcdã/ rpmbuild / SRPMS ïŒrpmbuild -ba nginx.spec
ããã¯ããããªæ¹æ³ã§ã¯ãããŸããããªããªã çµæã®.src.rpmã«ã¯ãngx_cache_purgeã¢ãžã¥ãŒã«ã®ãã¡ã€ã«ã¯å«ãŸããŸããã ãã ãããããéèŠãªå Žåã¯ãããã§ãã©ã³ã8.xxçšã®ãæ£ãããããŒãžã§ã³ã®nginx .src.rpmãããŠã³ããŒãã§ããŸãã 確ãã«ãå¿ èŠã®ãªãã¢ãžã¥ãŒã«ã®ããã€ãã«ã€ããŠã³ã¡ã³ãããŸããã
åæ§ç¯ãããnginxããµãŒããŒã«ã€ã³ã¹ããŒã«ããŸãã
ïŒrpm -ivh nginx-0.7.65-1.fc12.x86_64.rpm
PHPã§ãããžã§ã¯ãã®nginxãæ§æãã
ãã¡ã€ã«/ etc / hosts ïŒè¿œå ïŒïŒ
ïŒä»®æ³ãã¹ã 127.0.0.1 myproject
httpã»ã¯ã·ã§ã³ã®ã¡ã€ã³æ§æ/etc/nginx/nginx.confã«ä»¥äžãè¿œå ããŸãã
fastcgi_cache_path / var / spool / nginx /ãã£ãã·ã¥ã¬ãã«= 1ïŒ2 keys_zone = mycacheïŒ64m; include /etc/nginx/conf.d/*.conf;
ïŒ/ var / spool / nginx / cacheãã©ã«ããŒãäœæããnginxãå®è¡ãããŠãŒã¶ãŒãèšå®ããããšãå¿ããªãã§ãã ããïŒ
/etc/nginx/conf.d /ãã©ã«ããŒã§ãä»®æ³ãã¹ãã®æ§æãäœæããŸã
Kofigã®äŸïŒ /etc/nginx/conf.d/myproject.conf ïŒïŒ
ãµãŒããŒ{ 80ãèããŸãã server_name myproject; root / var / www / myproject / public; ssi on; ïŒå¿ èŠã«å¿ããŠãã£ãã·ã¥ãæå¹ã«ãã fastcgi_cache mycache; fastcgi_cache_min_uses 1; ïŒãã£ãã·ã¥æéã¯ãŒãã§ãã ãã£ãã·ã¥ã¯æå¹ã§ããããã£ãã·ã¥ã¯ãããŸãã ïŒç¹å®ã®ããŒãžã®ãã£ãã·ã¥æéããCache-ControlãããããŒã§æå®ããŸã fastcgi_cache_valid 200 0m; fastcgi_cache_valid 404 1m; fastcgi_cache_valid 500 0m; fastcgi_cache_use_staleæŽæ°ãšã©ãŒã¿ã€ã ã¢ãŠãinvalid_header http_500; ïŒãšã©ãŒãçºçããå Žåããã£ãã·ã¥ãªãã·ã§ã³ã䜿çšããŸãïŒå»æ¢ãããå Žåã§ãïŒ fastcgi_cache_key $ uri $ is_args $ args; ïŒngxxãngx_cache_purgeã¢ãžã¥ãŒã«ã§ãã«ããããŠããå Žåããã®ã»ã¯ã·ã§ã³ã®ã³ã¡ã³ããå€ããŸã ïŒå Žæã^ /ããŒãžïŒ/.*ïŒ{ ïŒfastcgi_cache_purge mycache $ 1 $ is_args $ args; ïŒ} å Žæã/ïŒimg | css | js |ã¢ã»ããïŒ{ ïŒaccess_log off; access_log /var/log/nginx/myproject_img_access.log main; æå¹æéã¯1æéã§ãã } å Žæ/ { access_log /var/log/nginx/myproject_main_access.log main; error_log /var/log/nginx/myproject_error.log; fastcgi_pass 127.0.0.1:7777; fastcgi_index index.php; fastcgi.confãå«ããŸãã } }
phpã®/ var / www / myprojectã«ãããã¹ããããžã§ã¯ããã€ã³ã¹ããŒã«ããŸã ã ãµã³ãã«ã®ãœãŒã¹ã³ãŒãã¯ãããã§è¡šç€ºããã³ããŠã³ããŒãã§ããŸã ã
nginxãèµ·åããŸãã RedHatã®ãããªã·ã¹ãã ã®å Žåã次ã®ããã«ãªããŸãã
ïŒservice nginx start
ãã¹ãŠãã·ã¹ãã ã¯äœåããæºåãã§ããŠããŸãïŒ httpïŒ// myproject /ãå®è¡ããããšããŠããŸã
ãã£ãã·ã¥æéã管çããããã®ããã¯ãšã³ããåŠã³ãŸãã
å®éãnginxã§ã¯ããã£ãã·ã¥æéã¯fastcgi_cache_valid 200 0mãã©ã¡ãŒã¿ãŒã§æå®ãããŠããŸãã ã¿ã€ãã«ãåå®çŸ©ãããŠããªããã¹ãŠã®ããŒãžã«é©çšãããŸãã
ããã©ã«ãã®æ§æã§ã¯ããã£ãã·ã¥æéã0ã«èšå®ããŠããŸãã ãã£ãã·ã¥ã¯ç¡å¹ã§ãã ãã ããããã¯ãšã³ãã次ã®ãããªããããŒãçæããå ŽåïŒ
ãã£ãã·ã¥å¶åŸ¡ïŒpublicãmax-age = 20ã©ã¡ãã
æå¹æéïŒæšã2010幎3æ18æ¥20:57:07 GMT
ãã®ããŒãžnginxã¯20ç§éãã£ãã·ã¥ãããŸãã phpã§ã¯ãheaderïŒïŒé¢æ°ã䜿çšããŠããããŒãå€æŽã§ããŸãïŒ nginxã®äœæè ã«ããã°ããX-Accel-Cache-ControlãããCache-ControlãããExpiresããæåªå ã§ãïŒ ã
å°ããªé¢æ°ãæžããŸãããã ãã£ãã·ã¥æéãå¶åŸ¡ããŸãïŒ
function cacheHeadersïŒ$ lifetime = 0ïŒ{ ïŒ$ date = gmdateïŒ "Dãd MYHïŒiïŒs"ãtimeïŒïŒ+ $ lifetimeïŒ; ïŒheaderïŒ 'ExpiresïŒ'ã$ dateã 'GMT'ïŒ; headerïŒ 'Cache-ControlïŒpublicãmax-age ='ã$ lifetimeïŒ; }
ãããã¯ãäœããŸã
ãããã¯ã¯ãæšæºã®htmlããŒãžããããŒãªãã§ãhtmlã³ãŒãã®è«ççã«å²ãåœãŠãããéšåãšåŒã°ããŸããããšãã°ã
<div> ããã¯åçŽãªãããã¯ã§ãã </ div>
åãããã¯ã®é®®åºŠã®ç¶æ ãèŠèŠçã«å¶åŸ¡ããããã«ããã¹ããããã¯ã®åºåæéã§ããã³ãŒããè¿œå ããŸãã
<ïŒphp echo dateïŒ 'GïŒiïŒs'ïŒïŒ>
SSIãããã¯ã䜿çšããå®éã®äŸãèŠãŠã¿ãŸãããã
ãã£ãã·ã¥ããããŒãžãåé€ãã
æ®å¿µãªãããnginxã«ã¯ãã£ãã·ã¥ããããŒãžãåé€ãããã€ãã£ãïŒéåžžã®ïŒæ¹æ³ããŸã ãããŸããã ããã¯äžäŸ¿ãªå ŽåããããŸãã
ã³ã³ãã€ã«äžã«ngx_cache_purgeã¢ãžã¥ãŒã«ãè¿œå ããå ŽåãconfigïŒ/etc/nginx/conf.d/myproject.confïŒã§ããlocation / {...ãã»ã¯ã·ã§ã³ã®åã«æ¬¡ã®ã»ã¯ã·ã§ã³ãè¿œå ããŸãã
å Žæã^ /ããŒãžïŒ/.*ïŒ{ #allow 127.0.0.1; #allow 10.1.1.0/24; #deny all; fastcgi_cache_purge mycache $ 1 $ is_args $ args; }
ãã£ãã·ã¥ãããããŒãžãåé€ããã«ã¯ãhttpïŒ//myproject/mypage.phpïŒLang = ruãhttpïŒ//myproject/purge/mypage.phpïŒLang = ruã®ããŒãžãããŠã³ããŒãããã ãã§ãã
phpã§ã¯ãããã¯file_get_contentsã³ãã³ãïŒ "httpïŒ//myproject/purge/mypage.phpïŒLang = ru"ïŒã§å®è¡ã§ããŸãã
allowããã³denyãã£ã¬ã¯ãã£ãã䜿çšããŠããã£ãã·ã¥ããã¯ãªã¢ãã§ãããã¹ãã®ç¯å²ãå¶éã§ããŸãã
ãã¹ãäž
ãã¹ãã®ãªã³ã¯http://linux.ria.ua/SsiBlocks/src/bin/index.phpãæãåºããŠãã ãã ã
ããŒãžã®ããã¬ãŒã ãã¯10ç§ããšã«æŽæ°ãããæ®ãã®ãããã¯ã¯ãããã¯äœææã®æ³šæäºé ã«åŸã£ãŠæŽæ°ãããããšã«æ³šæããŠãã ããã
ç§ã®æèŠã§ã¯ãæ倧ã®é¢å¿ã¯Zboynyãããã¯ã§ãã ã·ãã¥ã¬ãŒããããé害ã¢ãŒãã«å ¥ããšããã£ãã·ã¥ãã¯ãªã¢ãããŸã§ããã®ãããã¯ã®ãé害ã®ãªããããŒãžã§ã³ã衚瀺ãããŸãã
ããã«ããã®ããŒãžã§å®éšããŠããã®ã¯ããªãã ãã§ã¯ãªãããšãèŠããŠãããŠãã ãããå®éšããå Žåã¯ããµã³ãã«ã®ããŒã«ã«ã³ããŒãèªåã§èšå®ããŠãã ããã
çµè«ãåºã
ãã®ãããªã¢ãããŒãã¯ããªãã«ãšã£ãŠåå§çã§ããããã®æ©èœãéåžžã«å¶éãããŠããå Žåã§ãããããåã«é«éã ãã§ãªãéåžžã«é«éã«åäœãããšããäºå®ã«æ³šæããŠãã ããïŒ
ãã£ãã·ã¥ã倧ããªãµã€ãºã«ãèšåŒµããããã£ã¹ã¯ãã£ãã·ã¥ã«åãŸããªãå Žåãããã«ããã¯ã¯ãã£ã¹ã¯ã·ã¹ãã ã®ã¿ã«ãªããŸãã
PSïŒãã®èšäºãèªè ã«ãšã£ãŠèå³æ·±ããã®ã§ããå ŽåãZend Frameworkã§ãã£ãã·ã¥ããããã¯ããããã®èšè¿°ãããã¢ãããŒãã®ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠã®ç¬¬2éšãæžãäºå®ã§ãã