d:id:sfujiwara:20100812:1281587030 ã® reviseã
Nginxã®ifã¯æ¡ä»¶ç¯ã«&&(and)ã使ããªããifã®ãã¹ããã§ããªãã®ã§ãè¤æ°ã®æ¡ä»¶ã§å¤å¥ãããå ´åã¯å¤æ°ã使ãã¨ãããã£ã¦æãã§ãã
server { ... #error_page 500 502 503 504 /static/50x.html; ### maintenance error_page 500 502 504 /static/50x.html; set $go_maintenance "true"; if ($uri ~ "^/error/") { set $go_maintenance "false"; } if ($remote_addr ~ "^192\.0\.2\.") { set $go_maintenance "false"; } if ($remote_addr ~ "^10\.0\.0\.") { set $go_maintenance "false"; } if ($http_user_agent ~ "nakanohito-desu") { set $go_maintenance "false"; } if ($http_x_open = "sesame!") { set $go_maintenance "false"; } error_page 503 /error/503.html; location /error/ {} if ($go_maintenance = "true") { return 503; } # maintenance ### /maintenance location /static { alias /usr/irori/contents/example.com/static; expires 1h; gzip on; gzip_types text/css application/javascript application/x-javascript; keepalive_timeout 3 3; } location / { proxy_pass http://127.0.0.1:2006; ... } location ... { ... } }
- ãã½ã¯ã### maintenanceãããã### /maintenanceãã¾ã§ã
- ã«ã¹ã¿ã ã®ã¡ã³ããã¼ã¸ãåºããã && æ¢åã®è¨å®(error_page)ã§503ã®å¶å¾¡ããã¦ããå ´åã¯ã³ã¡ã³ãã¢ã¦ããã¦503ã ãã¯ã«ã¹ã¿ã ã®ã¡ã³ããã¼ã¸ã表示ããããã«ããã
- ã«ã¹ã¿ã ã¡ã³ããã¼ã¸ã¯ /error/ ä¸ã«é ç½®ãããã¡ã³ããã¼ã¸ã§ç»åã¨ã使ãå ´åããã®ãã£ã¬ã¯ããªé ä¸ã«ç½®ãã
- æ¢åè¨å®ã®locationã«é£ãããªãããã«ãlocation /error/ {}ã¨è¨å®ãã¦ããã
- 503ã«ãããã©ããã¯å¤æ°$go_maintenanceã§å¤æãããåæå¤ã¯"true"ã(ã¡ã³ãåã¯"false"ã«ãã¦ããã°ããã)
- ã«ã¹ã¿ã ã¡ã³ããã¼ã¸ã¯503ã«ãªã£ã¡ãã¾ããã®ã§ã^/error/ 㯠"false"
- ã»ããã¡ã³ãä¸ã«ä¸ã®äººãåä½ç¢ºèªãããæ¡ä»¶ãã²ã£ãã㦠"false" ã«ãã
- $remote_addr ã§ã¢ã¯ã»ã¹å
ã®IPã¢ãã¬ã¹ã¨ã
- $remote_addrãããããç¾ åãããå ´åã¯ãHttpGeoModuleã使ã£ãæ¹ãå¹ççã
- $http_user_agent ã§User-Agentãããã¨ã
- $http_x_open ã¨ãã§ã«ã¹ã¿ã ã®HTTPãªã¯ã¨ã¹ããããã¨ã
- $remote_addr ã§ã¢ã¯ã»ã¹å
ã®IPã¢ãã¬ã¹ã¨ã
- ã§ãif ($go_maintenance = "true") { return 503; }
- server {}ã®ä¸ã§return 503ãã¦ãã®ã§ãå¾ç¶ã«locationãããã¯ããããããã£ã¦ãããã ãã§OK