ç¬èªã®èªè¨¼æ©è½ä»ã HTTP ãã¦ã³ãã¼ããæä¾ããããã«ãnginx ã®çµã¿è¾¼ã¿ Perl ã使ã£ã¦ã¿ã¾ããã
å
¬å¼ã®ããã¥ã¡ã³ãã¯ãã¡ããEmbeddedPerlModule - Nginx Community
èªåã® handler ã§ãªã¯ã¨ã¹ããã¿ã¦å¦çãè¡ãã許å¯ãããªã DECLINED ãè¿ãã¦å¾ç¶ã®å¦çã«ä»»ãããããã§ãªããã° Fobidden ãè¿ãã¦ããã¾ããã¨ããæµãã§ãã
package MyAuth; use strict; use warnings; use nginx; sub handler { my $r = shift; if ( $r->header_in("MyAuth") ) { # ãªã«ãç¬èªã®èªè¨¼ããã(ããã§ã¯ãªã¯ã¨ã¹ãããããè¦ãã ã return DECLINED; # å¦çãç¶ç¶ãããããã« DECLINED } $r->status( HTTP_FORBIDDEN ); # 失æããã FORBIDDEN $r->send_http_header; $r->print("403 Forbidden"); return OK; } 1;
nginx.conf ã¯ãããªæãã§ã
events { use epoll; } http { sendfile on; perl_modules /home/fujiwara/lib; perl_require MyAuth.pm; server { listen 80; location /download/ { perl MyAuth::handler; alias /var/www/download/; } } }
ãã¡ãã DECLINED ãè¿ããªãã§ãèªåã§ãã¡ã¤ã«é
ä¿¡ã¾ã§å¦çãããã¨ãã§ãã¾ãã
$r->sendfile($path); ã§ãã¡ã¤ã«å
容ãè¿ããã¨ã¯ç°¡åã«ã§ããã®ã§ãããçé¢ç®ã«ãããã¨ããã¨æ¡ä»¶ä»ã GET (If-Modified-Since) ã¨ã Range ãããä»ãã®ãªã¯ã¨ã¹ãã« Partial Content ãè¿ãã¨ãããªã«ãã¨é¢åãªã®ã§ DECLINED ã§é常㮠nginx ã®ãã³ãã©ã«å
¨é¨ä»»ãã¾ããã
ab ã§ãã³ããã¼ã¯ãåã£ã¦ã¿ãã¨ãããä¾ã®ããã« $r->header_in ãåç §ããã ãã®å¦çãªãã°ãªã¼ãã¼ãããã¯ã»ã¼ç¡è¦ã§ãããããã§ããã測å®èª¤å·®ç¨åº¦ã§ãã
ãã ã注æç¹ããã£ã¦ãçµã¿è¾¼ã¿ Perl 㯠worker_processes ã®æ° (default: 1) ããåæã«åãã¾ããããã®ãããéä¸ã§ãããã¯ãããããªå¦ç (å¤é¨ã¸ HTTP ãªã¯ã¨ã¹ããé£ã°ããã) ãããã¨æ¥µç«¯ã«ä¸¦åæ§ãè½ã¡ãã®ã§ãããã¯è¦æ³¨æã§ããã