{"id":498,"date":"2008-06-25T15:22:11","date_gmt":"2008-06-25T06:22:11","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=498"},"modified":"2020-06-15T22:48:05","modified_gmt":"2020-06-15T13:48:05","slug":"thin_behind_nginx","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/thin_behind_nginx\/","title":{"rendered":"nginx \u306e\u5f8c\u308d\u3067 thin \u3092 unix socket \u3067\u52d5\u304b\u3059"},"content":{"rendered":"<p>Rails\u3092\u8d77\u52d5\u3059\u308b\u3068\u304d\u3001\u3044\u3064\u3082Pound\u306e\u5f8c\u308d\u3067\u8907\u6570\u30dd\u30fc\u30c8\u3067\u632f\u308a\u5206\u3051\u3063\u3066\u3044\u3046\u306e\u3092\u3088\u304f\u3084\u3063\u3066\u3044\u305f\u306e\u3060\u3051\u3069\u3001unix socket \u3067 nginx \u306e\u5f8c\u308d\u3067 thin \u3092\u52d5\u304b\u3059\u3068\u65e9\u3044\u3089\u3057\u3044\u3068\u306e\u3053\u3068\u3067\u3001\u8a66\u3057\u3066\u307f\u305f\u3002<\/p>\n<p>\u74b0\u5883\u306fOSX<\/p>\n<h2>thin\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<pre><code class=\"language-bash line-numbers\">$ sudo gem install thin\n$ sudo gem install eventmachine --source http:\/\/code.macournoyer.com\n<\/code><\/pre>\n<p>2\u884c\u76ee\u306f\u3001thin\u3092socket\u6307\u5b9a\u3057\u3066\u52d5\u304b\u3059\u6642\u306b eventmachin \u306e 0.11.0 \u4ee5\u4e0a\u304c\u5fc5\u8981\u3068\u306e\u3053\u3068\u3067\u3001OSX\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5165\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u5165\u308c\u305f\u3002<\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u3053\u308c\u3067\u5b8c\u4e86\u3002<\/p>\n<h2>nginx\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>Port\u3067\u5165\u308b\u306e\u304c 0.5.1 \uff1f\u3068\u304b\u3067\u3001\u3061\u3087\u3063\u3068\u53e4\u304b\u3063\u305f\u306e\u3067\u516c\u5f0f\u30b5\u30a4\u30c8(http:\/\/nginx.net\/)\u304b\u3089\u73fe\u6642\u70b9\u3067\u5b89\u5b9a\u7248\u306e 0.6.31\u3092\u53d6\u5f97\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre><code class=\"language-bash line-numbers\">$ wget http:\/\/sysoev.ru\/nginx\/nginx-0.6.31.tar.gz\n$ tar xvzf nginx-0.6.31\n$ cd nginx-0.6.31\n$ .\/configure --prefix=\/usr\/local\n$ make\n# make install\n<\/code><\/pre>\n<p>\u3067\u3001\u7121\u4e8b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u7d42\u308f\u308b\u306f\u305a\u3002configure \u3067 pcre \u30c1\u30a7\u30c3\u30af\u3055\u308c\u3066\u305f\u306e\u3067\u3001 pcre \u3068\u304b\u5165\u3063\u3066\u306a\u3044\u5834\u5408\u306f\u3044\u308c\u305f\u307b\u3046\u304c\u3088\u3055\u3052\u3002VirtualHost\u306e\u8a2d\u5b9a\u3059\u308b\u3068\u304d\u306b\u4f7f\u308f\u308c\u308b\u306e\u304b\u306a\uff1f<\/p>\n<h2>nginx\u306e\u8a2d\u5b9a<\/h2>\n<p>configure \u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3067 &#8211;prefix=\/usr\/local \u3068\u3057\u305f\u5834\u5408\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f \/usr\/local\/conf\/nginx.conf \u306b\u751f\u6210\u3055\u308c\u3066\u3044\u3066\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3053\u308c\u3092\u8aad\u307f\u306b\u884c\u304d\u307e\u3059\u3002<\/p>\n<p>\u7de8\u96c6\u3057\u307e\u3059\u3002\u6700\u4f4e\u9650\u306e\u8a2d\u5b9a\u3060\u3051\u3002<\/p>\n<pre><code class=\"language-nginx line-numbers\">worker_processes  1;\nevents {\n    worker_connections  1024;\n}\nhttp {\n    include       mime.types;\n    default_type  application\/octet-stream;\n\n    sendfile        on;\n    keepalive_timeout  0;\n\n    upstream backend {\n        server unix:\/tmp\/thin.0.sock;\n        server unix:\/tmp\/thin.1.sock;\n        server unix:\/tmp\/thin.2.sock;\n        server unix:\/tmp\/thin.3.sock;\n    }\n\n    server {\n        listen       80;\n        location \/ {\n            proxy_pass http:\/\/backend;\n\n        }\n    }\n}\n<\/code><\/pre>\n<p>\u3053\u308c\u3067\u300180\u756a\u30dd\u30fc\u30c8\u306b\u304d\u305f\u3082\u306e\u3092\u3001unix socket \u306e \/tmp\/thin.[0-3].sock \u3067\u52d5\u3044\u3066\u308b\u4f55\u304b\u306b\u8ee2\u9001\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001-t \u3092\u3064\u3051\u3066\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u6587\u6cd5\u30c1\u30a7\u30c3\u30af\u3092\u3057\u307e\u3059\u3002OK\u306a\u3089\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u51fa\u307e\u3057\u305f\u3002<\/p>\n<pre><code class=\"language-bash line-numbers\">$ sudo \/usr\/local\/sbin\/nginx -t\n2008\/06\/25 01:05:12 [info] 14511#0: the configuration file \/usr\/local\/conf\/nginx.conf syntax is ok\n2008\/06\/25 01:05:12 [info] 14511#0: the configuration file \/usr\/local\/conf\/nginx.conf was tested successfully\n<\/code><\/pre>\n<h2>thin\u306e\u8a2d\u5b9a(\u8d77\u52d5)<\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\"><img decoding=\"async\" data-src=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1920px; --smush-placeholder-aspect-ratio: 1920\/768;\" \/><\/a><\/p>\n<p>Rails \u3067\u3057\u304b\u4f7f\u3063\u305f\u3053\u3068\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b Rails \u30a2\u30d7\u30ea\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u76f4\u4e0b\u3067\u53e9\u3044\u3066\u304f\u3060\u3057\u3042\u3002\u30b3\u30de\u30f3\u30c9\u306b\u5f15\u6570\u6e21\u3059\u3060\u3051\u3060\u3051\u3069\u3001\u5148\u307b\u3069 nginx.conf \u3067\u6307\u5b9a\u3057\u305f unix socket \u3067\u52d5\u304b\u3059\u3002<\/p>\n<p><code>- s 4<\/code> \u306f\u30d7\u30ed\u30bb\u30b94\u3064\u306e\u610f\u5473\u3067\u3001<code>--socket \/tmp\/thin.sock<\/code> \u3068\u3059\u308b\u3068\u30b5\u30fc\u30d0\u306e\u6570\u3060\u3051 \/tmp\/thin.n.sock \u304c\u51fa\u6765\u308b\u3088\u3046\u3060\u3002<\/p>\n<pre><code class=\"language-bash line-numbers\">$ thin start -s 4 --socket \/tmp\/thin.sock \n<\/code><\/pre>\n<h2>nginx\u306e\u8d77\u52d5<\/h2>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u8d77\u52d5\u3057\u307e\u3059\u3002\u307c\u304f\u306e\u74b0\u5883\u3060\u3068\u3001\u4f55\u3082\u6a19\u6e96\u51fa\u529b\u3055\u308c\u305a\u306b\u8d77\u52d5\u3057\u307e\u3057\u305f\u3002\u8d77\u52d5\u3057\u305f\u3089 lsof -i:80 \u3068\u304b\u3057\u306680\u756a\u3067\u7acb\u3061\u4e0a\u304c\u3063\u3066\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-bash line-numbers\">$ sudo \/usr\/local\/sbin\/nginx\n<\/code><\/pre>\n<p>\u3053\u308c\u3067\u52d5\u304f\u3002<\/p>\n<p>\u3053\u306e\u72b6\u614b\u3067\u3001thin \u3092\u843d\u3068\u3057\u3066\u307f\u308b\u3002Rails \u3060\u3068\u3001thin \u306e pid \u30d5\u30a1\u30a4\u30eb\u304c tmp\/pids\/ \u4ee5\u4e0b\u306b\u51fa\u6765\u307e\u3059\u3093\u3067\u3001\u4eca \/tmp\/thin.[0-2].sock \u3067\u52d5\u3044\u3066\u308b\u3068\u3053\u308d\u3092\u843d\u3068\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-bash line-numbers\">$ kill cat `tmp\/pids\/thin.0.pid`\n$ kill cat `tmp\/pids\/thin.1.pid`\n$ kill cat `tmp\/pids\/thin.2.pid`\n<\/code><\/pre>\n<p>\u3053\u308c\u30673\u3060\u3051\u304c\u52d5\u3044\u3066\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u6b63\u5e38\u306b\u3064\u306a\u304c\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u3061\u3083\u3093\u3068\u632f\u5206\u3051\u3089\u308c\u3066\u308b\u307f\u305f\u3044\u3067\u3059\u306d\u30fc\u3002<\/p>\n<p>Pound \u306b\u6bd4\u3079\u3066\u3044\u3044\u306a\u3063\u3066\u601d\u3046\u3068\u3053\u308d\u304c\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u304c\u843d\u3061\u305f\u3068\u304d\u306e\u6319\u52d5\u3067\u3059\u3002Pound \u306f Alive \u3067\u6307\u5b9a\u3057\u305f\u79d2\u6570\u3067\u30dd\u30fc\u30ea\u30f3\u30b0\u3067\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3092\u6b7b\u6d3b\u76e3\u8996\u3092\u3057\u3066\u308b\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u5f8c\u308d\u304c\u843d\u3061\u3061\u3083\u3063\u305f\u3042\u3068\u6b21\u306e\u30dd\u30fc\u30ea\u30f3\u30b0\u307e\u3067\u306f\u30a8\u30e9\u30fc\u753b\u9762\u304c\u51fa\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>nginx \u3067\u4eca\u56de\u8a66\u3057\u3066\u307f\u305f\u611f\u3058\u3001\u5f8c\u308d\u304c\u843d\u3061\u3066\u3082\u524d\u306b\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306f\u306a\u3044\u307f\u305f\u3044\uff1f\u5168\u90e8\u843d\u3061\u308b\u3068\u3001\u3082\u3061\u308d\u3093\u30a8\u30e9\u30fc\u753b\u9762\u304c\u51fa\u307e\u3059\u3051\u3069\u3002<\/p>\n<p>\u53c2\u8003URL: http:\/\/wiki.codemongers.com\/Main (nginx \u306e wiki)<\/p>\n<p>\u4e2d\u56fd\u884c\u3063\u3066\u308b\u3068\u304d\u3001\u5bb6\u306e\u30b5\u30fc\u30d0\u843d\u3061\u305f\u3089\u7d42\u308f\u308a\u304b\u3068(&#8216;A`)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rails\u3092\u8d77\u52d5\u3059\u308b\u3068\u304d\u3001\u3044\u3064\u3082Pound\u306e\u5f8c\u308d\u3067\u8907\u6570\u30dd\u30fc\u30c8\u3067\u632f\u308a\u5206\u3051\u3063\u3066\u3044\u3046\u306e\u3092\u3088\u304f\u3084\u3063\u3066\u3044\u305f\u306e\u3060\u3051\u3069\u3001unix socket \u3067 nginx \u306e\u5f8c\u308d\u3067 thin \u3092\u52d5\u304b\u3059\u3068\u65e9\u3044\u3089\u3057\u3044\u3068\u306e\u3053\u3068\u3067\u3001\u8a66\u3057\u3066\u307f\u305f\u3002 \u74b0\u5883\u306fO [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2702,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[7,20,10],"class_list":["post-498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-linux","tag-nginx","tag-rails"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=498"}],"version-history":[{"count":3,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/498\/revisions"}],"predecessor-version":[{"id":2711,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/498\/revisions\/2711"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2702"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}