{"id":2075,"date":"2017-09-10T09:29:50","date_gmt":"2017-09-10T00:29:50","guid":{"rendered":"https:\/\/mattyan.net\/blog\/?p=2075"},"modified":"2017-09-10T09:29:50","modified_gmt":"2017-09-10T00:29:50","slug":"docker%e4%b8%8a%e3%81%aenginx-unit%e3%81%a7wordpress%e3%82%92%e5%8b%95%e3%81%8b%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f%e3%80%82","status":"publish","type":"post","link":"https:\/\/mattyan.net\/blog\/?p=2075","title":{"rendered":"Docker\u4e0a\u306eNginx Unit\u3067WordPress\u3092\u52d5\u304b\u3057\u3066\u307f\u305f\u3002"},"content":{"rendered":"<p>\u4f1a\u793e\u3067<a href=\"https:\/\/www.nginx.com\/products\/nginx-unit\/\">Nginx Unit<\/a>\u306a\u308b\u3082\u306e\u3092\u805e\u3044\u305f\u306e\u3067\u3001\u8a66\u3057\u3066\u307f\u305f\u3002<br \/>\n<!--more--><br \/>\nNginx Unit\u306b\u3064\u3044\u3066\u306f\u5272\u611b\u3002<br \/>\n\u5927\u96d1\u628a\u306a\u8a8d\u8b58\u3060\u3068\u3001Nginx\u793e\u304c\u4f5c\u3063\u3066\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc\u3067\u3001uWsgi\u3068\u304bphp-fpm\u306e\u4ee3\u308f\u308a\u306b\u306a\u308b\u3082\u306e\u3068\u8a00\u3063\u305f\u611f\u3058\u3002<br \/>\n\u4eca\u56de\u306fCoreOS + Docker\u4e0a\u306bUbuntu\u74b0\u5883\u3092\u4f5c\u3063\u3066\u3001Nginx Unit\u3092\u5165\u308c\u3066WordPress\u3092\u8d70\u3089\u305b\u3066\u307f\u305f\u3002<br \/>\n\u672c\u5f53\u306fCoreOS + Docker + Alpine linux\u3067\u8a66\u3057\u305f\u304b\u3063\u305f\u3051\u3069\u3001Alpine linux\u306b\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u306a\u3044\u306e\u3068\u3001\u30d3\u30eb\u30c9\u304c\u6210\u529f\u3057\u306a\u304b\u3063\u305f\u306e\u3067Ubuntu\u3067\u30c6\u30b9\u30c8\u3002<br \/>\nAlpine Linux\u306emusl-dev\u306elibpthread\u306b\u306fmakecontext\u3068\u304bgetcontext\u3068\u304bsetcontext\u304c\u7121\u3044\u3063\u307d\u3044\u3051\u3069\u3001\u305d\u3093\u306a\u3082\u3093\u306a\u306e\u304b?<\/p>\n<hr \/>\n<h3>\u30d5\u30a1\u30a4\u30eb\u69cb\u6210<\/h3>\n<p>[text]<br \/>\nserver_nginx_unit<br \/>\n    \u2502  docker-compose.yml<br \/>\n    \u2502<br \/>\n    \u2514\u2500blog<br \/>\n        \u2502  config.json<br \/>\n        \u2502  Dockerfile<br \/>\n        \u2502<br \/>\n        \u2514\u2500nginx<br \/>\n                default.conf<br \/>\n[\/text]<br \/>\nblog\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306bDockerfile\u3068Nginx unit\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u3001nginx\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bnginx\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u3044\u3068\u3044\u305f\u3002<\/p>\n<h3>Dockerfile<\/h3>\n<p>[text]<br \/>\nFROM ubuntu:xenial<br \/>\nENV WORDPRESS_IMAGE wordpress-4.8.1-ja.tar.gz<br \/>\nRUN apt-get update &amp;&amp; apt-get -y upgrade<br \/>\nRUN apt-get install -y git<br \/>\nRUN apt-get install -y nginx build-essential php-dev libphp-embed<br \/>\nRUN apt-get install -y php7.0-json php7.0-mcrypt php7.0-mysql php7.0-curl php7.0-gd php7.0-zip<br \/>\nRUN git clone https:\/\/github.com\/nginx\/unit<br \/>\nRUN cd unit &amp;&amp; \\<br \/>\n\tbash .\/configure &#8211;bindir=\/bin &#8211;sbindir=\/bin &#8211;modules=\/usr\/share\/nginx-unit\/modules &amp;&amp; \\<br \/>\n\tbash .\/configure php &#8211;module=php70 &#8211;config=\/usr\/bin\/php-config7.0 &#8211;lib-path=\/usr\/lib &amp;&amp; \\<br \/>\n\tmake all &amp;&amp; \\<br \/>\n\tmake install &amp;&amp; \\<br \/>\n\tcd ..\/<br \/>\nRUN curl https:\/\/ja.wordpress.org\/$WORDPRESS_IMAGE -o $WORDPRESS_IMAGE<br \/>\nRUN tar xzf $WORDPRESS_IMAGE<br \/>\nRUN rm -f $WORDPRESS_IMAGE<br \/>\nCOPY nginx\/default.conf \/etc\/nginx\/sites-available\/default<br \/>\nCOPY config.json \/etc\/nginx-unit\/config.json<br \/>\n[\/text]<br \/>\nUbuntu\u306b\u306f\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u3042\u308b\u3093\u3060\u3051\u3069\u3001\u8981\u6c42\u3059\u308bpython\u304c2.7\u3060\u3063\u305f\u308a\u3001\u305d\u3082\u305d\u3082\u4eca\u56depython\u3082Go\u3082\u5fc5\u8981\u306a\u3044\u306e\u3067\u81ea\u524d\u3067\u30d3\u30eb\u30c9\u3002<br \/>\nphp7.0\u7cfb\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u591a\u5206\u8db3\u308a\u306a\u3044\u3051\u3069\u3001index.php\u304c\u52d5\u3044\u305f\u3042\u305f\u308a\u3067\u529b\u5c3d\u304d\u305f\u3002<br \/>\n.\/configure &#8211;modules\u3067\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5148\u3092\u6307\u5b9a\u3057\u306a\u3044\u3068\u3001build\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304b\u3089build\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bphp70.unit.so\u3092\u30b3\u30d4\u30fc\u3057\u3088\u3046\u3068\u3057\u3066\u6b7b\u306c\u306e\u306f\u306a\u3093\u306a\u3093\u3060\u308d\u3046\u2026<\/p>\n<h3>config.json<\/h3>\n<p>[javascript]<br \/>\n{<br \/>\n\t&quot;listeners&quot;: {<br \/>\n\t\t&quot;*:8080&quot;: {<br \/>\n\t\t\t&quot;application&quot;: &quot;blog&quot;<br \/>\n\t\t}<br \/>\n\t},<br \/>\n\t&quot;applications&quot;: {<br \/>\n\t\t&quot;blog&quot; : {<br \/>\n\t\t\t&quot;type&quot;: &quot;php&quot;,<br \/>\n\t\t\t&quot;workers&quot;: 1,<br \/>\n\t\t\t&quot;root&quot;: &quot;\/wordpress&quot;,<br \/>\n\t\t\t&quot;index&quot;: &quot;index.php&quot;<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<br \/>\n[\/javascript]<br \/>\n\u30dd\u30fc\u30c88080\u3067listen\u3057\u3066\u3001\/wordpress\u4ee5\u4e0b\u306ephp\u3092\u547c\u3073\u51fa\u3059\u8a2d\u5b9a\u3002<br \/>\n\u30dd\u30fc\u30c88080\u306fDocker\u30b3\u30f3\u30c6\u30ca\u304b\u3089\u5916\u306b\u306f\u51fa\u3055\u306a\u3044\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u306f\u4e0d\u53ef\u306e\u306f\u305a\u3002<\/p>\n<h3>default.conf<\/h3>\n<p>[text]<br \/>\nserver {<br \/>\n    listen       80;<br \/>\n    server_name  localhost;<br \/>\n    client_max_body_size 10m;<br \/>\n    #charset koi8-r;<br \/>\n    error_log  \/var\/log\/nginx\/error.log warn;<br \/>\n    root   \/wordpress;<br \/>\n    location \/ {<br \/>\n        index  index.html index.htm index.php;<br \/>\n    }<br \/>\n    location ~ .*\\.php {<br \/>\n        proxy_pass   http:\/\/127.0.0.1:8080;<br \/>\n        proxy_set_header Host $host;<br \/>\n        proxy_redirect http:\/\/$host:8080 http:\/\/$host;<br \/>\n    }<br \/>\n}<br \/>\n[\/text]<br \/>\nphp\u304c\u547c\u3070\u308c\u305f\u3089\u3001Nginx Unit\u306b\u4e38\u6295\u3052\u3002\u305d\u306e\u4ed6\u306e\u3068\u304d\u306f\u305d\u306e\u307e\u307e\u30d5\u30a1\u30a4\u30eb\u53d6\u5f97\u3057\u3066\u8fd4\u3059\u3002<br \/>\nproxy\u5468\u308a\u306e\u8a2d\u5b9a\u5fd8\u308c\u305f\u2026\u4e00\u5fdc\u3053\u308c\u3067\u52d5\u3044\u305f\u3002<\/p>\n<h3>docker-compose.yml<\/h3>\n<p>[text]<br \/>\nversion: &#8216;2&#8217;<br \/>\nservices:<br \/>\n  # Web\u30da\u30fc\u30b8<br \/>\n  blog:<br \/>\n    build: blog<br \/>\n    links:<br \/>\n     &#8211; mysql<br \/>\n    ports:<br \/>\n      &#8211; &quot;80:80&quot;<br \/>\n    command: sh -c &quot;if [ -e control.unit.sock ]; then rm -f control.unit.sock; fi &amp;&amp; unitd &#8211;log \/tmp\/unitd.log &amp;&amp; sleep 1s &amp;&amp; curl -X PUT -d @\/etc\/nginx-unit\/config.json &#8211;unix-socket control.unit.sock http:\/\/localhost\/ &amp;&amp; nginx -g &#8216;daemon off;&#8217;&quot;<br \/>\n  mysql:<br \/>\n    image: mysql:latest<br \/>\n    environment:<br \/>\n        &#8211; MYSQL_ROOT_PASSWORD=mysqlroot<br \/>\n[\/text]<br \/>\nunixd\u3092\u8d77\u52d5\u3057\u3066\u304b\u3089\u3001curl\u3067\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u98df\u308f\u305b\u3066\u3001nginx -g &#8216;daemon off;&#8217;\u3067Docker\u3092\u6bba\u3055\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u8d77\u52d5\u3002<br \/>\ndocker-compose up\u3067\u8d77\u52d5\u3057\u305f\u3042\u3068Ctrl+C\u3067\u6bba\u3059\u3068\u3001control.unit.sock\u304c\u6b8b\u3063\u3066\u6b21\u56de\u8d77\u52d5\u6642\u306bunitd\u304c\u8d77\u52d5\u3067\u304d\u306a\u304f\u306a\u308b\u306e\u3067\u3001control.unit.sock\u304c\u6b8b\u3063\u3066\u305f\u3089\u6d88\u3059\u3088\u3046\u306b\u3057\u305f\u3002<br \/>\nmysql\u306fDockerHub\u304b\u3089\u62fe\u3063\u3066\u304d\u305f\u3082\u306e\u3002<br \/>\n\u3053\u308c\u3067<br \/>\n[text]<br \/>\ndocker-compose up blog<br \/>\n[\/text]<br \/>\n\u3092\u3059\u308b\u3068Nginx Unit\u3068Nginx\u304c\u8d77\u52d5\u3057\u305f\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3002<br \/>\n<a href=\"wp-content\/uploads\/2017\/09\/NginxUnit.png\"><img decoding=\"async\" src=\"wp-content\/uploads\/2017\/09\/NginxUnit.png\" style=\"width: 100%;\"<\/a><br \/>\n\u3068\u308a\u3042\u3048\u305a\u52d5\u3044\u305f\u3063\u307d\u3044\u3002<br \/>\n\u2026\u304c\u3001\u9032\u3081\u3066\u307f\u308b\u3068\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u7121\u9650\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u30eb\u30fc\u30d7\u306b\u30cf\u30de\u308a\u82e6\u6226\u3002<br \/>\nwp-include\/template-loader.php\u306e12\u884c\u76ee\u306e<br \/>\n[php]<br \/>\n&lt;?php<br \/>\n\/**<br \/>\n * Loads the correct template based on the visitor&#8217;s url<br \/>\n * @package WordPress<br \/>\n *\/<br \/>\nif ( defined(&#8216;WP_USE_THEMES&#8217;) &amp;&amp; WP_USE_THEMES )<br \/>\n        \/**<br \/>\n         * Fires before determining which template to load.<br \/>\n         *<br \/>\n         * @since 1.5.0<br \/>\n         *\/<br \/>\n        do_action( &#8216;template_redirect&#8217; );<br \/>\n\/**<br \/>\n[\/php]<br \/>\n\u3092<br \/>\n[php]<br \/>\n&lt;?php<br \/>\n\/**<br \/>\n * Loads the correct template based on the visitor&#8217;s url<br \/>\n * @package WordPress<br \/>\n *\/<br \/>\nif ( defined(&#8216;WP_USE_THEMES&#8217;) &amp;&amp; WP_USE_THEMES )<br \/>\n        \/**<br \/>\n         * Fires before determining which template to load.<br \/>\n         *<br \/>\n         * @since 1.5.0<br \/>\n         *\/<br \/>\n        \/\/do_action( &#8216;template_redirect&#8217; );<br \/>\n\/**<br \/>\n[\/php]<br \/>\n\u306b\u3057\u305f\u3089\u52d5\u3044\u305f\u3051\u3069\u3001\u3053\u308c\u7d50\u69cb\u524d\u306b\u6cbb\u3063\u305f\u30d0\u30b0\u3058\u3083\u306a\u3044\u306e?<br \/>\n<a href=\"wp-content\/uploads\/2017\/09\/WordPress.png\"><img decoding=\"async\" src=\"wp-content\/uploads\/2017\/09\/WordPress.png\" style=\"width:100%;\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f1a\u793e\u3067Nginx Unit\u306a\u308b\u3082\u306e\u3092\u805e\u3044\u305f\u306e\u3067\u3001\u8a66\u3057\u3066\u307f\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2075","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2075"}],"version-history":[{"count":0,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2075\/revisions"}],"wp:attachment":[{"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattyan.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}