F5ãNGINXã®éçºãã¼ã ããã·ã¢å½å¤ã¸ç§»è»¢ããããã¨ãå ±åãéçºãç«ã¦ç´ããªãªã¼ã¹ãµã¤ã¯ã«ãå éãã« NGINXï¼ã¨ã³ã¸ã³ã¨ãã¯ã¹ï¼ã¯ãªã¼ãã³ã½ã¼ã¹ã§éçºããã¦ããWebãµã¼ãã¨ãã¦ãã£ã¨ã人æ°ã®ããã½ããã¦ã§ã¢ã®1ã¤ã§ãããã®éçºè ã§ããIgor Sysoevï¼ã¤ã¼ã´ãªã»ã·ã½ã¨ãï¼æ°ããã·ã¢ã®é¦é½ã¢ã¹ã¯ã¯ã«ä½ãã§ãããã¨ãªã©ã«ãããNGINXã®éçºã¯ãã·ã¢ã®é¦é½ã¢ã¹ã¯ã¯ãä¸å¿ã«è¡ããã¦ãã¾ããã ãã®ãã·ã¢ã¯ç¾å¨ãã¦ã¯ã©ã¤ãã¸ã®æ¦åä¾µæ»ã«å対ãã西å´è«¸å½ã«ããå³ããçµæ¸å¶è£ä¸ã«ãããå¤ãã®ITä¼æ¥ããã·ã¢ã«ãããæ´»åãåæ¢ãã¦ãã¾ãã 2019å¹´ã«NGINX社ãè²·åãç¾å¨NGINXã®éçºå ã¨ãªã£ã¦ããF5ãããã·ã¢ã«ãããå¶æ¥æ´»åã¨NGINXãªã¼ãã³ã½ã¼ã¹ããã¸ã§ã¯ãã¸ã®è²¢ç®ãåæ¢ãããã¨ãã3æ15æ¥ä»ãã®ããã°ãStanding Firm in Support of the Pe
nginxã¯workerããã»ã¹ã®æ°ãCPUã³ã¢ï¼ã¹ã¬ããï¼æ°ã§æ±ºå®ããworker_processes autoã¨ãã便å©è¨å®ãããã¾ãã ãããå¤ç¨ããã¦ããã®ã¯ãnginxããã³ããããã³ã°ã§ãªã¯ã¨ã¹ãå¦çãè¡ããããã³ã³ããã¹ãã¹ã¤ãããªã©ãèæ ®ããå ´åã«ãã³ã¢æ°ã§ç«ã¡ä¸ãã¦ããã°å¹çããCPUã使ãåããã¨ããåæãããããã§ãã ä¸æ¹ã§ãä¾ãã°åã®ç¨éã§ã¯ãç¾å¨ç»åã®å¦çã ã£ããã¨ããngx_mrubyã®ããã«ãªã¯ã¨ã¹ãã®éç¨ã§ä¸é¨ããããã³ã°ããããããªå¦çãå¢ãã¦ãã¦ãããããã³ã¢æ°ä»¥ä¸ã®å¤ã«è¨å®ãã¦ãããæ¹ãæ§è½ãçºæ®ã§ãããããªç¶æ³ãå¢ãã¦ãã¦ãã¾ãã ãããªãã¨ãç¾ç¶ãé常ã«ä¾¿å©ãªè¨å®ã§ããautoè¨å®ã使ããã«éçã«æ°åãè¨å®ããå¿ è¦ããããä¾ãã°ãµã¼ããªãã¬ã¼ã¹æã«ã¯å¤ãã³ã¢æ°ãèæ ®ããå¤ã«ãªã£ã¦ããããã¦ããªãã¬ã¼ã¹å¾ã«CPUã®ã³ã¢è¨å®ããã®ã¾ã¾ã§æ§è½ãåºãã¦ã
# ç°å¢å¤æ° RAILS_MAX_THREADS ã« 16 ãã»ãã threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } ... # ç°å¢å¤æ° WEB_CONCURRENCY ã« 2 ãã»ãã workers ENV.fetch("WEB_CONCURRENCY") { 2 } å®é¨ãè¡ã£ãçµæããã¡ãããµã¼ãã¼ã®ãªã½ã¼ã¹(ä»åã¯CPUã³ã¢æ°: 2)ã«ãããã¾ãã以ä¸ã®ããã«ãµã¼ãã¼ãå¦çã§ãããã£ãã·ãã£ãå¤ããã¾ãããthreadæ°ãå°ãªãã¨ãã¡ãããã°ããå¦çæ°ãæ¸ãããããµã¼ãã¼ã®ãªã½ã¼ã¹ãä½ã£ã¦ããã«ãããããããunhealthyã«ãªãã¾ããã¤ã¾ããã¬ã¹ãã³ã¹ã§éè² è·ã示ã503 errorãè¿å´ããã¾ãã 1worker/5threadã®å ´åãCPU15%ãããã§unhealthyã«ãªã 1worker/10threadã®
æ£ç´æ¥ãããã話ã§ãããDiskç£è¦ã¡ããã¨å ¥ãã¦ããã°é²ãã話ã§ãã AWSã®EC2ã§nginxåããã¦ããããDisk使ç¨çã100%ã«ãªã£ã¦ã¬ã¹ãã³ã¹ãè¿ããªããªãã¾ããã åå ã¯nginxã巨大ãªãã°ãã¡ã¤ã«ãåºåãã¦ãããããªã®ã§ããã dfã ã¨diskãå°ããã¦ããã®ã«ã/ã«ç§»åãã¦du -sh *ã§ãã£ã¬ã¯ããªãã¨ã®ä½¿ç¨éãè¦ã¦ã¿ã¦ãã ã©ããdiskãå°ã£ã¦ããã®ããããã¾ããã§ããã ããã§ä½ãã®ããã»ã¹ããã¡ã¤ã«ãã¤ããã§ããã ããã¨èª¿ã¹ãã¨ãããnginxã巨大ãªãã°ãã¡ã¤ã«ãã¤ããã§ãã¾ããã ãªããããduã§ããããªãã£ããã¨ããã¨ãå®éã®ãã¡ã¤ã«ã¯åå¨ãã¦ããªãã£ãããã§ãã nginxã®èµ·åã¦ã¼ã¶ã¼ã¯ec2-userã«ãªã£ã¦ããã®ã§ãããnginxã¯yumã§ã¤ã³ã¹ãã¼ã«ãããã®ãªã®ã§ã logåºåå ã®ãã£ã¬ã¯ããªã®ãªã¼ãã¼ãnginxã¦ã¼ã¶ã¼ã«ãªã£ã¦ããã ã
Nginxã®ã¢ã¼ããã¯ãã£ã«ã¤ãã¦èª¿ã¹ã¦ããã¨ãã¾ã¨ããã ç¨èªã®ãããã ããã»ã¹ï¼Processï¼ ããã°ã©ã ã®å®è¡åä½ã§ãããCPUæéåä½ã§å²ãæ¯ãããã ç¶æ (ã¹ãã¼ã)ããããç¾å¨å¦çä¸ã§ããRunningç¶æ ã ã£ãããå®è¡å¯è½ç¶æ ã§ããReadyçãåå¨ããã CPUãããã»ã¹ãå®è¡ããå ´åããã®ããã»ã¹ãæã¤ã¡ã¢ãªãã¼ã¿ã«å¯¾ãã¦æ¼ç®ãè¡ãã ããã»ã¹ã¯ããã¹ãã»ã°ã¡ã³ãã¨ãã¼ã¿ã»ã°ã¡ã³ããããªãæ§é ãã¼ã¿ãã¡ã¢ãªä¸ã«æã£ã¦ããã ããã¹ãã»ã°ã¡ã³ã ããã°ã©ã ã®å½ä»¤å ãã¼ã¿ã»ã°ã¡ã³ã PDA (Processor Data Area)ã¨å¼ã°ãããããã»ããµã®æ å ±ãããã»ã¹ç®¡çç¨ã®ãã¼ã¿é å ãã¼ã¿é åã¨å¼ã°ãããå®æ°çãç½®ãããéçé åã¨ãé常ã®å¤æ°çãç½®ããããã¼ãé åãããªãé å ã¹ã¿ãã¯é åã¨å¼ã°ãããä¸æçãªãã¼ã¿ä¿ç®¡é å å®è¡ä¸ã®ããã»ã¹ãç¢ºèª ~ â¯â¯â¯ ps
Knowledge ã¨ãããªã¼ãã³ã½ã¼ã¹ã®ã½ããã¦ã§ã¢ã使ç¨ãã¦ããã®ã§ããããã®ä¸ã§ãã¡ã¤ã«ãã¢ãããã¼ãããã¨ãããã¢ãããã¼ãã«å¤±æãã¾ãããã¨ã¡ãã»ã¼ã¸ã表示ããã¢ãããã¼ãã§ãã¾ããã§ããã åå ã調ã¹ãã¨ãã nginx ã®ããã©ã«ãã 1M ã¾ã§ã¨ãããã¨ãåããã client_max_body_size ãé©åã«è¨å®ãããã¨ã§å¯¾å¿ãããã¨ãã§ãã¾ããã Knowledge ã¯æ¬¡ã®ç°å¢ã§éç¨ãã¦ãã¾ãã nginx tomcat ãµã¼ãã§åãæ±ããµã¤ãºã®å¤æ´ http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size ã«ããã¨ã nginx ã§ã¯ããã©ã«ãã§1MBã¾ã§ã®ãã¼ã¿ããåãä»ããªãè¨å®ã«ãªã£ã¦ãã¾ãã nginx ã1MBãã大ããªãã¼ã¿ãæ±ããããã«ããã«ã¯ã conf
ã¯ããã« æ¬æ¥ã®08ï¼00ï½09ï¼30é ã¾ã§å½ãµã¤ãã404ã¨ã©ã¼ã§ãã¼ã¸ã表示ãããªããªã£ã¦ãã¾ããã nginxã®åèµ·åãããã¨ããããã®ç¶æ ã«ãªã£ã¦ãã¾ãã¾ããã ã¨ã©ã¼ãã°ãç¢ºèª ã¨ã©ã¼ãã°ã確èªããã¨ããä¸è¨ã®ãããªã¨ã©ã¼ãçºçãã¦ãã¾ããã [crit] open() "/hogehoge_html/DocumentRoot/index.php" failed (13: Permission denied), client: xxx.xx.x.xx, server: www.kabanoki.net, request: "GET / HTTP/1.1", host: "www.kabanoki.net" ãã¡ã¤ã«ã®ãã¼ããã·ã§ã³ãå¤æ´ ã¨ã©ã¼ã®ãã°ã«(13: Permission denied)ã¨ããã®ã§ã権éã«åé¡ãããã®ããªï¼ã¨è©¦ãã«index.phpã®ãã¼ããã·ã§ã³ã77
ã¢ã¯ã»ã¹æ¨©éã¯ã ã»ãã£ã¬ã¯ããªã«ã¯å®è¡æ¨©é ã»ãã¡ã¤ã«ã«ã¯èªåã権é ãä»ä¸ããã°å¤§ä¸å¤«ãªã¯ãã§ããããã®ãããªã¨ã©ã¼ãåºã¦ãã¾ãã¾ããã [error] 4418#0: *9 open() "/home/ec2-user/www/index.html" failed (13: Permission denied)ãã£ã¬ã¯ããªã»ãã¡ã¤ã«ã®ææè ãã°ã«ã¼ããrootã«å¤æ´ãã¦ããã¡ã§ãã ã¨ããããã®è§£æ±ºæ¡ åºæ¬çã«ãã«ã¼ããã£ã¬ã¯ããªã®å ´æãã¦ã¼ã¶ã¼ã®ãã¼ã ãã£ã¬ã¯ããªã«è¨å®ããã¦ããã¨ã¨ã©ã¼ã«ãªãã¾ãã ï¼ã¨ããã®ã¯ã¡ãã£ã¨èªå¼ãããã¾ããã¨ã©ã¼ã«ãªãçç±ã¯ãã¡ãï¼ âãã¡ãªä¾ location / { root /home/[ã¦ã¼ã¶ã¼å]/www; index index.html; }â»ããã©ã«ãã ã¨ã/home/[ã¦ã¼ã¶ã¼å]/ãã®ãã¼ããã·ã§ã³ã700ãªã®ã§ã701ã«å¤æ´ããã°
æ¦è¦ nginxãåãã¦ä½¿ã£ã¦ã¿ã¾ãããã è²ã ãããã©ããããã£ããããã¡ã¢ãå ¼ãã¦æ稿ãã¾ãã Owneråé¡ ããã¯nginxã«éã£ãåé¡ã§ã¯ãªãããããã¾ãããã 使ç¨ãããã©ã«ããnginxã®å®è¡ã¦ã¼ã¶ã«ãªã£ã¦ããå¿ è¦ãããã¾ãã ä¾ãã°ãcentosã®å ´åã 㨠/var/lib/nginx ãªã©ã§ããã ããããã¾ããã£ã¦ããªã㨠ãã¦ã³ãã¼ãã®å¦çãªã©ãå ¥ããæã« failed (13: Permission denied) while reading upstream ã¨ããã¨ã©ã¼ãnginxããåãåºããã¾ãã 解決ææ³ sudo chown -R [nginxã®å®è¡ã¦ã¼ã¶å] /var/lib/nginx ããã¯ããããããOwnerãå¤ããããªã®ããããã¾ãããã ããã¾ã§æ¤è¨¼ããã¦ãã¾ããã ããããããææãªã©ããã¾ããããã³ã¡ã³ããã ããã Permission
Centos7 + Nnginx 1.10.3 ã§error.logãè¦ã¦ã¿ã㨠2017/02/17 10:51:27 [crit] 17910#17910: *1 stat() "/home/user/sample/html/" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: sample.com, request: "GET / HTTP/1.1", host: "sample.com", referrer: "https://sample.com" ã¨ãã£ãã¨ã©ã¼ããããã.. ãã£ã¬ã¯ããªã®ãã¼ããã·ã§ã³ãè¦ã¦ã¿ã¦ã $ ls -al /home/user/sample/html/ drwxrwxr-x 7 user nginx 4096 2æ 16 12:10 . ãªæãã§åé¡ãªããã ãããã調
defaultã¯60ç§ sudo vi /etc/nginx/nginx.conf httpãããã¯ã®ã¿ã¤ã ã¢ã¦ãæéãå¤æ´ããï¼ç§ï¼ http{ ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... } ç¹å®ã®ãµã¼ãã ããæéå¤ãããæ server{ ... proxy_read_timeout 300; proxy_connect_timeout 300; proxy_send_timeout 300; ... } åèµ·å sudo systemctl restart nginx ç¢ºèª systemctl status nginx
# ã¯ã¼ã«ããã»ã¹æ° worker_processes 1; # ã¨ã©ã¼ãã°åºåå error_log /var/log/nginx/error.log; # PIDãã¡ã¤ã«ã®é ç½®å pid /var/run/nginx.pid; # 1ã¯ã¼ã«ããã»ã¹ãåæãªã¼ãã³å¯è½ãªãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿æ°æå¤§å¤ worker_rlimit_nofile 1024; events { # 1ã¯ã¼ã«ããã»ã¹ãåæãªã¼ãã³å¯è½ãªã³ãã¯ã·ã§ã³æ°æå¤§å¤ worker_connections 512; } http { # ã¢ã¯ã»ã¹ãã°åºåå access_log /var/log/nginx/access.log; # nginxã«å¸¸ææ¥ç¶ãã¦ããã¯ã©ã¤ã¢ã³ãã«å¯¾ããã¿ã¤ã ã¢ã¦ãæé keepalive_timeout 10s; server { listen 80; location / { # å ¨ã¦ã®ã¢ã
Enables or disables the use of asynchronous file I/O (AIO) on FreeBSD and Linux: location /video/ { aio on; output_buffers 1 64k; } On FreeBSD, AIO can be used starting from FreeBSDÂ 4.3. Prior to FreeBSDÂ 11.0, AIO can either be linked statically into a kernel: options VFS_AIO or loaded dynamically as a kernel loadable module: kldload aio On Linux, AIO can be used starting from kernel version 2.6.2
ãªã¯ã¨ã¹ããããã®ãã©ã¡ã¼ã¿ãæ¶ãã nginxã«ãªãã¼ã¹ãããã·ãã¦ãããæ§æã«ããããããã¯ã¨ã³ãå´ã§HTTPãªã¯ã¨ã¹ãããããå¹ããªãã¨ããç¾è±¡ãçºçãã. ãã©ã¡ã¼ã¿åã«'_'ãå«ããªã¯ã¨ã¹ããããã¯ç ´æ£ããã nginxã®ããã©ã«ãè¨å®ã§ã¯ããªã¯ã¨ã¹ããããã«'_'ãå«ã¾ãããã©ã¡ã¼ã¿åã¯ç¡è¦ããä»æ§ã«ãªã£ã¦ãã. nginxã®è¨å®ã«ã²ã¨æéå¿ è¦ã ã£ã.
Nginxçµç±ã§Pumaï¼Rails5ã¸ã¢ã¯ã»ã¹ã§ããããã«è¨å®ãã¦ã¿ãã Rails5ã§ã¢ããªã±ã¼ã·ã§ã³ã¯åé¡ãªãåãã¦ããåæã§è¨è¼ Rails5ã§ã®ããã©ã«ãã®ã¢ã¯ã»ã¹æ¹æ³ã¯ãhttp://æ¥ç¶IP:3000ã¨ãããã®ã§ããã¼ã3000ã«ã¢ã¯ã»ã¹ããããã«ãªã£ã¦ãããã©ãä¸è¬çã«ã¯ãã¼ã3000ã§ã¢ã¯ã»ã¹ãã¦ãããã®ãªãã¦ã¿ããã¨ãªãã 調ã¹ã¦ã¿ãã¨ãRailsã®åã«Webãµã¼ãããã£ã¦ãWebãµã¼ãçµç±ã§Railsã¸ã¢ã¯ã»ã¹ããã®ãä¸è¬çã¿ããã ä¾ãã°ã ä»ã¾ã§ãhttp://1.1.1.1:3000ã«ã¢ã¯ã»ã¹ããã¨Pumaãåãåã£ã¦ãRailsã«æ¸¡ãï¼ ã¨ããåãã ã£ããã©ã ä¸è¬çã«ã¯ http://1.1.1.1ã«ã¢ã¯ã»ã¹ããã¨ãWebãµã¼ã(Nginxï¼ãåãåã£ã¦ãNginxã1.1.1.1:3000ã«æ¸¡ãã¦ããããPumaãåãåã£ã¦ãRailsã«æ¸¡ãï¼ ã¨ããåã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}