{"id":423,"date":"2012-10-31T17:52:52","date_gmt":"2012-10-31T08:52:52","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=423"},"modified":"2018-11-14T16:33:59","modified_gmt":"2018-11-14T07:33:59","slug":"nginx%e3%81%aeif%e3%81%ab%e8%a6%81%e6%b3%a8%e6%84%8f","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2012\/10\/31\/nginx%e3%81%aeif%e3%81%ab%e8%a6%81%e6%b3%a8%e6%84%8f\/","title":{"rendered":"nginx\u306eif\u306b\u8981\u6ce8\u610f"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u5bfa\u5ca1\u3067\u3059\u3002<\/p>\n<p>\u6700\u8fd1WEB\u30b5\u30fc\u30d0\u306bnginx\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001<br \/>\n\u305d\u306e\u6642\u306b\u30cf\u30de\u3063\u305f\u30dd\u30a4\u30f3\u30c8\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>nginx \u306b\u306f if\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u304c\u3042\u308a\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u8a2d\u5b9a\u3084\u5909\u6570\u3092\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306eif\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306f\u304b\u306a\u308a\u306e\u66f2\u8005\u3067\u3001\u4e00\u822c\u7684\u306a\u611f\u899a\u3068\u306f\u7570\u306a\u308b\u6319\u52d5\u3092\u3057\u307e\u3059\u3002<\/p>\n<p>\u7686\u3055\u3093\u306f\u3001\u4ee5\u4e0b\u306e\u8a2d\u5b9a\u3067\u3069\u3093\u306a\u30d8\u30c3\u30c0\u304c\u51fa\u529b\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u304b\uff1f<\/p>\n<pre>location \/only-one-if {\r\n  set $true 1;\r\n  if ($true) {\r\n    add_header X-First 1;\r\n  }\r\n  if ($true) {\r\n    add_header X-Second 2;\r\n  }\r\n  return 204;\r\n}<\/pre>\n<p>\u4e00\u822c\u7684\u306a\u611f\u899a\u3060\u3068\u3001X-First: 1\u3068X-Second: 2\u304c\u51fa\u529b\u3055\u308c\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<br \/>\n\u5f53\u7136\u305d\u3046\u306a\u308b\u3093\u3060\u3068\u308d\u3046\u3068\u601d\u3063\u3066\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u2026\u2026\u3002<\/p>\n<pre class=\"lang:sh decode:true\">$telnet localhost 80\r\nGET \/only-one-if HTTP\/1.0\r\n\r\nHTTP\/1.1 204 No Content\r\nServer: nginx\r\nDate: Wed, 31 Oct 2012 01:01:01 GMT\r\nConnection: close\r\nX-Second: 2<\/pre>\n<p>\u9a5a\u3044\u305f\u3053\u3068\u306b\u3001\u51fa\u529b\u3055\u308c\u308b\u306e\u306fX-Second: 2\u306e\u307f\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u306f\u3053\u306eif\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3001\u672c\u5bb6\u3067\u3082 <a href=\"http:\/\/wiki.nginx.org\/IfIsEvil\">IfIsEvil<\/a> \u306a\u3093\u3066\u6ce8\u610f\u3055\u308c\u3066\u3044\u305f\u308a\u3057\u307e\u3059\u3002<br \/>\n\u8a2d\u5b9a\u6b21\u7b2c\u3067\u306fSIGSEGV\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u8981\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<p>\u6319\u52d5\u306e\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f\u4e0b\u306e\u30ea\u30f3\u30af\u5148\u3067\u8a73\u3057\u304f\u8aac\u660e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/agentzh.blogspot.jp\/2011\/03\/how-nginx-location-if-works.html\">How nginx \"location if\" works<\/a><\/p>\n<p>\u6b63\u78ba\u306b\u7406\u89e3\u3067\u304d\u3066\u3044\u308b\u304b\u81ea\u4fe1\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u304a\u305d\u3089\u304f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30eb\u30fc\u30eb\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>if \u306frewirte\u30d5\u30a7\u30fc\u30ba\u306b\u4e0a\u304b\u3089\u9806\u306b\u5b9f\u884c\u3055\u308c\u308b<\/li>\n<li>add_header\u7b49\u306econtent handler\u3068\u547c\u3070\u308c\u308b\u7a2e\u985e\u306e\u5b9a\u7fa9\u306f\u3001\u89aa\u5b50\u95a2\u4fc2\u3092\u6301\u3064\u30d6\u30ed\u30c3\u30af\u9593\u3067\u7d99\u627f\u3055\u308c\u308b<\/li>\n<li>location\u5185\u306bif\u304c\u3042\u308b\u5834\u5408\u3001\u6700\u3082\u6df1\u3044\u30d6\u30ed\u30c3\u30af\u306econtent handler\u304c\u9069\u7528\u3055\u308c\u308b\uff08\u540c\u4e00\u968e\u5c64\u306e\u5834\u5408\u306f\u4e0b\u306b\u8a18\u8ff0\u3055\u308c\u305f\u3082\u306e\u304c\u512a\u5148\u3055\u308c\u308b\uff09<\/li>\n<li>return\u3084break\u304c\u3042\u308b\u5834\u5408\u3001rewirte\u30d5\u30a7\u30fc\u30ba\u3092\u7d42\u4e86\u3057\u3001\u305d\u306e\u6642\u70b9\u3067\u6709\u52b9\u306acontent halder\u304c\u9069\u7528\u3055\u308c\u308b<\/li>\n<\/ul>\n<p>\u3053\u306e\u6319\u52d5\u306flocation\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5185\u306bif\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u8a18\u8ff0\u3057\u305f\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u6709\u7121\u3067\u6319\u52d5\u3092\u5909\u3048\u305f\u3044\u5834\u5408\u306f <a href=\"http:\/\/wiki.nginx.org\/HttpCoreModule#try_files\">try_files<\/a> \u3092\u6d3b\u7528\u3059\u308c\u3070\u4f55\u3068\u304b\u306a\u308a\u307e\u3059\u306e\u3067\u3001<br \/>\n\u3088\u307b\u3069\u306e\u7406\u7531\u304c\u306a\u3044\u9650\u308alocation\u5185\u306eif\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306f\u7981\u6b62\u3057\u305f\u307b\u3046\u304c\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002\u5bfa\u5ca1\u3067\u3059\u3002<\/p>\n<p>\u6700\u8fd1WEB\u30b5\u30fc\u30d0\u306bnginx\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001<br \/>\n\u305d\u306e\u6642\u306b\u30cf\u30de\u3063\u305f\u30dd\u30a4\u30f3\u30c8\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>nginx \u306b\u306f if\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u304c\u3042\u308a\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u8a2d\u5b9a\u3084\u5909\u6570\u3092\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2012\/10\/31\/nginx%e3%81%aeif%e3%81%ab%e8%a6%81%e6%b3%a8%e6%84%8f\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[40],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/423"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=423"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/423\/revisions"}],"predecessor-version":[{"id":4378,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/423\/revisions\/4378"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}