{"id":1158,"date":"2014-12-26T22:22:31","date_gmt":"2014-12-26T13:22:31","guid":{"rendered":"http:\/\/www.otwo.jp\/blog\/?p=1158"},"modified":"2017-03-29T16:33:17","modified_gmt":"2017-03-29T07:33:17","slug":"nginx-study","status":"publish","type":"post","link":"https:\/\/www.otwo.jp\/blog\/nginx-study\/","title":{"rendered":"nginx\u3067\u69cb\u7bc9\u3059\u308b\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3068\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5"},"content":{"rendered":"<p>\u3069\u3046\u3082\u3001\u958b\u767a2\u90e8\u3067\u30b5\u30fc\u30d0\u62c5\u5f53\u3057\u3066\u308b\u5c71\u672c\u3067\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d0\u30c1\u30fc\u30e0\u3067\u306f\u6bce\u9031\u52c9\u5f37\u4f1a\u3092\u884c\u3063\u3066\u3044\u3066\u3001<br \/>\n\u4eca\u56denginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3068\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u3092\u69cb\u7bc9\u3057\u305f\u306e\u3067\u305d\u306e\u5185\u5bb9\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u30aa\u30fc\u30c4\u30fc\u3067\u306f\u7814\u4fee\u7528\u306b\u30af\u30e9\u30a6\u30c9\u30b5\u30fc\u30d3\u30b9\u3092\u5951\u7d04\u3057\u3066\u304a\u308a\u3001<br \/>\n\u4eca\u56de\u306f\u305d\u306e\u30af\u30e9\u30a6\u30c9\u4e0a\u306b\u74b0\u5883\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002<\/p>\n<h1>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7<\/h1>\n<p>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u69cb\u7bc9\u3067\u306f\u3001\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b71\u53f0\u3068web\u30b5\u30fc\u30d02\u53f0\u3092\u7528\u610f\u3057\u3001<br \/>\n\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306b\u30b0\u30ed\u30fc\u30d0\u30ebIP\u3092\u8a2d\u5b9a\u3057\u3001<br \/>\n\u7570\u306a\u308b\u30c9\u30e1\u30a4\u30f3\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u305d\u308c\u305e\u308c\u306eweb\u30b5\u30fc\u30d0\u306b\u632f\u308a\u5206\u3051\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u73fe\u5834\u3067\u3082\u793e\u5185\u306b\u3042\u308b\u958b\u767a\u7528\u306eVM\u3092\u516c\u958b\u3059\u308b\u969b\u306b<br \/>\n\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3092\u4f7f\u3063\u3066\u74b0\u5883\u306e\u5207\u308a\u5206\u3051\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>web\u30b5\u30fc\u30d0\u306e\u8a2d\u5b9a<\/h2>\n<p>yum\u3067httpd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u30ef\u30fc\u30cb\u30f3\u30b0\u3092\u53d6\u308a\u9664\u3044\u3066\u8d77\u52d5\u3057\u307e\u3059\u3002<br \/>\n2\u53f0\u306eweb\u30b5\u30fc\u30d0\u3068\u3082\u540c\u3058\u624b\u9806\u3067\u69cb\u7bc9\u3057\u3001\u305d\u308c\u305e\u308cweb01,web02\u3068\u3057\u307e\u3059\u3002<\/p>\n<p># yum install httpd<br \/>\n# vi \/etc\/httpd\/conf\/httpd.conf<br \/>\nServerName\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068\u30ef\u30fc\u30cb\u30f3\u30b0\u304c\u51fa\u308b\u306e\u3067\u3068\u308a\u3042\u3048\u305a\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>httpd.conf\u306e\u5909\u66f4\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">ServerName localhost:80\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p># chkconfig httpd on<br \/>\n# apachectl start<\/p>\n<h2>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u8a2d\u5b9a<\/h2>\n<p>nginx\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3001\u5404web\u30b5\u30fc\u30d0\u3078\u306e\u632f\u5206\u3051\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p># vi \/etc\/yum.repos.d\/nginx.repo<\/p>\n<p>nginx.repo\u306e\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">[nginx]\r\nname=nginx repo\r\nbaseurl=http:\/\/nginx.org\/packages\/centos\/$releasever\/$basearch\/\r\ngpgcheck=0\r\nenabled=0\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p># yum install nginx &#8211;enablerepo=nginx<br \/>\n# vi \/etc\/nginx\/conf.d\/rev_proxy.conf<\/p>\n<p>rev_proxy.conf\u306e\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">#### web01\r\nserver {\r\nlisten 80;\r\nserver_name test1.otwo-study.com;\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Host $host;\r\nproxy_set_header X-Forwarded-Server $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nlocation \/ {\r\nproxy_pass http:\/\/172.18.0.105\/;\r\n}\r\n}\r\n\r\n#### web02\r\nserver {\r\nlisten 80;\r\nserver_name test2.otwo-study.com;\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Host $host;\r\nproxy_set_header X-Forwarded-Server $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nlocation \/ {\r\nproxy_pass http:\/\/172.18.0.132\/;\r\n}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>web\u30b5\u30fc\u30d0\u3078\u306e\u632f\u5206\u3051\u306e\u8a2d\u5b9a\u3067\u3059\u3002<br \/>\ntest1.otwo-study.com\u3067\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u3089web01\uff08172.18.0.105\uff09\u3078\u3001<br \/>\ntest2.otwo-study.com\u3067\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u3089web02\uff08172.18.0.132\uff09\u3078\u3068\u3044\u3046\u5185\u5bb9\u3067\u3059\u3002<br \/>\nproxy_set_header\u306f\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306eweb\u30b5\u30fc\u30d0\u306b\u63a5\u7d9a\u5143\u306eIP\u7b49\u306e\u60c5\u5831\u3092\u5f15\u304d\u6e21\u3059\u305f\u3081\u306e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<p># vi \/etc\/nginx\/conf.d\/default.conf<\/p>\n<p>default.conf\u306e\u5909\u66f4\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">server_name localhost default;\r\n<\/pre>\n<p>test1.otwo-study.com\u3001test2.otwo-study.com\u4ee5\u5916\u3067<br \/>\n\u30a2\u30af\u30bb\u30b9\u3055\u308c\u305f\u5834\u5408\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u6319\u52d5\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p># vi \/etc\/nginx\/nginx.conf<\/p>\n<p>nginx.conf\u306e\u5909\u66f4\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\"># include \/etc\/nginx\/conf.d\/*;\r\ninclude \/etc\/nginx\/conf.d\/rev_proxy.conf;\r\ninclude \/etc\/nginx\/conf.d\/default.conf;\r\n<\/pre>\n<p>rev_proxy.conf\u3068default.conf\u3060\u3051\u3092\u660e\u793a\u7684\u306binclude\u3057\u307e\u3059\u3002<\/p>\n<p># chkconfig nginx on<br \/>\n# \/etc\/init.d\/nginx start<br \/>\n&nbsp;<\/p>\n<h2>\u540d\u524d\u89e3\u6c7a\u306e\u8a2d\u5b9a<\/h2>\n<p>\u3061\u3083\u3093\u3068\u3057\u305f\u958b\u767a\u74b0\u5883\u3067\u306f\u30b5\u30d6\u30c9\u30e1\u30a4\u30f3\u3067\u5207\u308a\u5206\u3051\u305f\u308a\u3057\u307e\u3059\u304c\u3001<br \/>\n\u4eca\u56de\u306f\u52c9\u5f37\u4f1a\u306e\u305f\u3081\u3060\u3051\u306a\u306e\u3067\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306ehosts\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3057\u3066\u540d\u524d\u89e3\u6c7a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304cwindows\u306a\u306e\u3067\u3001C:\\Windows\\System32\\drivers\\etc\\hosts\u306b\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\n<p>hosts\u306e\u8ffd\u8a18\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">xxx.xxx.xxx.xxx test1.otwo-study.com\r\nxxx.xxx.xxx.xxx test2.otwo-study.com\r\n<\/pre>\n<p>xxx.xxx.xxx.xxx\u306f\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u30b0\u30ed\u30fc\u30d0\u30ebIP\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n&nbsp;<\/p>\n<h2>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u3053\u3053\u307e\u3067\u306e\u8a2d\u5b9a\u304c\u4e0a\u624b\u304f\u3044\u3063\u3066\u3044\u308c\u3070\u4ee5\u4e0b\u306e\u6319\u52d5\u306b\u306a\u308b\u306f\u305a\u3002<\/p>\n<ul class=\"mb-none\">\n<li>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u30b0\u30ed\u30fc\u30d0\u30ebIP\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u4e0a\u306enginx\u306ewelcome\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b<\/li>\n<li>test1.otwo-study.com\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068web01\u306eapache\u306ewelcome\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\uff08web\u30b5\u30fc\u30d0\u306eaccess_log\u3092tail\u3067\u78ba\u8a8d\uff09<\/li>\n<li>test2.otwo-study.com\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068web02\u306eapache\u306ewelcome\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u308b\uff08web\u30b5\u30fc\u30d0\u306eaccess_log\u3092tail\u3067\u78ba\u8a8d\uff09<\/li>\n<\/ul>\n<h1>\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5<\/h1>\n<p>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u306e\u7d9a\u304d\u3067\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u3092\u69cb\u7bc9\u3057\u307e\u3057\u305f\u3002<br \/>\n\u540c\u4e00\u30c9\u30e1\u30a4\u30f3\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092web01,web02\u306b\u30e9\u30a6\u30f3\u30c9\u30ed\u30d3\u30f3\u3067\u632f\u308a\u5206\u3051\u307e\u3059\u3002<\/p>\n<h2>\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u306e\u8a2d\u5b9a<\/h2>\n<p>nginx\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p># vi \/etc\/nginx\/conf.d\/balance.conf<\/p>\n<p>balance.conf\u306e\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">upstream balance-otwo-study {\r\nserver 172.18.0.105;\r\nserver 172.18.0.132;\r\n}\r\nserver {\r\nlisten 80;\r\nserver_name balance.otwo-study.com;\r\nproxy_set_header Host $host;\r\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\nproxy_set_header X-Forwarded-Host $host;\r\nproxy_set_header X-Forwarded-Server $host;\r\nproxy_set_header X-Real-IP $remote_addr;\r\nlocation \/ {\r\nproxy_pass http:\/\/balance-otwo-study\/;\r\n}\r\n}\r\n<\/pre>\n<p>upstream\u3067\u632f\u5206\u3051\u5bfe\u8c61\u306e\u30b5\u30fc\u30d0\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u5747\u7b49\u306a\u30e9\u30a6\u30f3\u30c9\u30ed\u30d3\u30f3\u3067\u3059\u304c\u3001<br \/>\n\u30b5\u30fc\u30d0\u6bce\u306e\u91cd\u307f\u4ed8\u3051\u3084\u3001ip\u306e\u30cf\u30c3\u30b7\u30e5\u5024\u3001\u63a5\u7d9a\u6570\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u306a\u3069\u306b\u3088\u308b\u632f\u5206\u3051\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p># vi \/etc\/nginx\/nginx.conf<\/p>\n<p>nginx.conf\u306e\u5909\u66f4\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">include \/etc\/nginx\/conf.d\/balance.conf;\r\n<\/pre>\n<p>balance.conf\u3092include\u3057\u307e\u3059\u3002<\/p>\n<p># \/etc\/init.d\/nginx restart<\/p>\n<h2>\u540d\u524d\u89e3\u6c7a\u306e\u8a2d\u5b9a<\/h2>\n<p>\u5148\u307b\u3069\u3068\u540c\u3058\u304f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306ehosts\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3057\u3066\u540d\u524d\u89e3\u6c7a\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\nhosts\u306e\u8ffd\u8a18\u5185\u5bb9<\/p>\n<pre class=\"brush: python\r; notranslate\">xxx.xxx.xxx.xxx balance.otwo-study.com\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u306e\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u3053\u3053\u307e\u3067\u306e\u8a2d\u5b9a\u304c\u4e0a\u624b\u304f\u3044\u3063\u3066\u3044\u308c\u3070<br \/>\nbalance.otwo-study.com\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068web01\u3068web02\u306b\u30e9\u30a6\u30f3\u30c9\u30ed\u30d3\u30f3\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u304c\u632f\u308a\u5206\u3051\u3089\u308c\u307e\u3059\u3002<br \/>\n\uff08web\u30b5\u30fc\u30d0\u306eaccess_log\u3092tail\u3067\u78ba\u8a8d\uff09<\/p>\n<p>\u5168\u90e8\u540c\u3058\u753b\u9762\u3067\u898b\u305f\u76ee\u5206\u304b\u3089\u306a\u3044\u3067\u3059\u3051\u3069\u3001\u3061\u3083\u3093\u3068\u52d5\u3044\u3066\u307e\u3059^^;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1133 size-full\" src=\"http:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2014\/12\/201410162125.jpg\" alt=\"201410162125\" width=\"771\" height=\"433\" srcset=\"https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2014\/12\/201410162125.jpg 771w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2014\/12\/201410162125-300x168.jpg 300w, https:\/\/www.otwo.jp\/blog\/wp-content\/uploads\/2014\/12\/201410162125-267x150.jpg 267w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>nginx\u697d\u30c1\u30f3\u3063\u3059\u306d\uff01\uff01<\/p>\n<p>&nbsp;<\/p>\n<p>\u30aa\u30fc\u30c4\u30fc\u3067\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u6bce\u90311\u6642\u9593\u7a0b\u5ea6\u3001\u52c9\u5f37\u4f1a\u3092\u958b\u50ac\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305f\u5225\u306e\u52c9\u5f37\u4f1a\u306e\u5185\u5bb9\u3082\u8a18\u4e8b\u306b\u3057\u3088\u3046\u3068\u601d\u3063\u3066\u308b\u306e\u3067\u898b\u306b\u6765\u3066\u3084\u3063\u3066\u304f\u3060\u3055\u3044m(_ _)m<\/p>\n<p>\u3067\u306f\u3067\u306f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3001\u958b\u767a2\u90e8\u3067\u30b5\u30fc\u30d0\u62c5\u5f53\u3057\u3066\u308b\u5c71\u672c\u3067\u3059\u3002 \u30b5\u30fc\u30d0\u30c1\u30fc\u30e0\u3067\u306f\u6bce\u9031\u52c9\u5f37\u4f1a\u3092\u884c\u3063\u3066\u3044\u3066\u3001 \u4eca\u56denginx\u3067\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3068\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u3092\u69cb\u7bc9\u3057\u305f\u306e\u3067\u305d\u306e\u5185\u5bb9\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":4,"featured_media":1133,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[22],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/1158"}],"collection":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/comments?post=1158"}],"version-history":[{"count":5,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/1158\/revisions"}],"predecessor-version":[{"id":2910,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/posts\/1158\/revisions\/2910"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media\/1133"}],"wp:attachment":[{"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/media?parent=1158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/categories?post=1158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.otwo.jp\/blog\/wp-json\/wp\/v2\/tags?post=1158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}