{"id":3460,"date":"2020-04-02T08:17:18","date_gmt":"2020-04-01T23:17:18","guid":{"rendered":"https:\/\/www.sambuichi.jp\/?p=3460"},"modified":"2022-02-11T19:14:49","modified_gmt":"2022-02-11T10:14:49","slug":"%e3%82%b7%e3%82%a7%e3%83%ab%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%a7%e3%82%a6%e3%82%a7%e3%83%96%e3%82%a2%e3%83%97%e3%83%aa","status":"publish","type":"post","link":"https:\/\/www.sambuichi.jp\/?p=3460","title":{"rendered":"\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea"},"content":{"rendered":"<p>Views: 82<\/p><p>AWS Linux2\u3067\u306f\u3001amazon-linux-extras \u3092\u4f7f\u7528\u3059\u308b\u3002<br \/>\n\u53c2\u8003\uff1a<a href=\"https:\/\/hogetech.info\/2021\/11\/22\/%E3%80%90%E5%85%A5%E9%96%80%E3%80%91nginx-%E3%81%A8%E3%81%AF\/\">\u3010\u5165\u9580\u3011nginx \u3068\u306f \u8a2d\u5b9a\u65b9\u6cd5\u3092\u7d39\u4ecb<\/a><\/p>\n<pre class=\"height-set:true width-set:true lang:default decode:true \" >\r\n$ sudo amazon-linux-extras install nginx1 -y\r\n$ sudo systemctl start nginx\r\n$ sudo amazon-linux-extras install epel -y\r\n$ sudo yum install fcgiwrap -y\r\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e2d:\r\n fcgiwrap      x86_64      1.1.0-12.20181108git99c942c.el7      epel       22 k\r\n\u4f9d\u5b58\u6027\u95a2\u9023\u3067\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u3057\u307e\u3059:\r\n fcgi          x86_64      2.4.0-25.el7                         epel       47 k\r\n$ sudo yum install spawn-fcgi -y\r\n================================================================================\r\n Package             \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u30fc   \u30d0\u30fc\u30b8\u30e7\u30f3             \u30ea\u30dd\u30b8\u30c8\u30ea\u30fc   \u5bb9\u91cf\r\n================================================================================\r\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e2d:\r\n spawn-fcgi          x86_64          1.6.3-5.el7            epel           18 k\r\n\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306e\u8981\u7d04\r\n================================================================================\r\n$ sudo vim \/etc\/sysconfig\/spawn-fcgi\r\n```\r\nOPTIONS=\"-u nginx -g nginx -s \/var\/run\/fcgiwrap.socket -S -M 0770 -F 1 -P \/var\/run\/spawn-fcgi.pid -- \/usr\/sbin\/fcgiwrap\"\r\n```\r\n$ sudo systemctl start spawn-fcgi\r\n\r\n$ sudo vim \/usr\/share\/nginx\/html\/test.py\r\n```\r\n#!\/usr\/bin\/python3\r\nimport random\r\nprint(\"HTTP\/1.0 200 OK\")\r\nprint(\"Content-type: text\/html\\n\")\r\nprint(\"\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u8868\u793a\u3057\u307e\u3059\u3002\")\r\nprint(random.random())\r\n```\r\n$ sudo chmod 755 \/usr\/share\/nginx\/html\/test.py\r\n\r\n$ sudo vim \/etc\/nginx\/conf.d\/fcgi.conf\r\n```\r\nserver {\r\n    listen       localhost:8080;\r\n    location ~ \\.py$ {\r\n      root   \/usr\/share\/nginx\/html\/; #$document_root\r\n      fastcgi_pass unix:\/var\/run\/fcgiwrap.socket;\r\n      include           \/etc\/nginx\/fastcgi_params;\r\n      fastcgi_param     SCRIPT_FILENAME   $document_root$fastcgi_script_name;\r\n    }\r\n}\r\n```\r\n$ sudo systemctl restart nginx\r\n$ curl localhost:8080\/test.py\r\n\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u8868\u793a\u3057\u307e\u3059\u3002\r\n0.7280845311460491<\/pre>\n<hr>\n<link rel=\"stylesheet\" href=\"https:\/\/use.fontawesome.com\/releases\/v5.6.3\/css\/all.css\"\n      integrity=\"sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s\/\"\n      crossorigin=\"anonymous\">\n<div class=\"index\" style=\"width: 90%; margin: auto; padding-left: 8px; border: solid 1px #d0d0d0;\">\n<div style=\"text-align: center;\">\u76ee\u6b21<\/div>\n<p style=\"margin: 0;\">\n  <a href=\"#S1\">\u6982\u8981<\/a><br \/>\n  <a href=\"#S2\">fcgiwrap<\/a><br \/>\n  <a href=\"#S3\">spawn-fcgi<\/a><br \/>\n  <a href=\"#S4\">nginx\u306econf\u8a2d\u5b9a<\/a>\n<\/p>\n<\/div>\n<p><span id=\"S1\"><\/span><\/p>\n<h4>\u6982\u8981<\/h4>\n<p>\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u3092\u958b\u767a\u3001\u5225\u306e\u30b5\u30fc\u30d0\u3078\u5c55\u958b\u3059\u308b\u305f\u3081\u5b9f\u884c\u74b0\u5883\u8a2d\u5b9a\u3092\u518d\u78ba\u8a8d\u3057\u305f\u306e\u3067\u3001\u305d\u306e\u30e1\u30e2\u3002<br \/>\nPHP\u306fphp-fpm\u3068\u3044\u3046\u30bd\u30d5\u30c8\u3068Nginx\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u30b5\u30fc\u30d3\u30b9\u3092\u63d0\u4f9b\u3059\u308b\u304c\u3001\u30b7\u30e7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30a6\u30a7\u30d6\u30a2\u30d7\u30ea\u3067\u52d5\u4f5c\u3055\u305b\u308b\u306b\u306f\u3001fcgiwrap\u304a\u3088\u3073spawn-fcgi\u3068\u3044\u3046\u30bd\u30d5\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p><span id=\"S2\"><\/span><\/p>\n<h4>fcgiwrap<\/h4>\n<p>fcgi\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre class=\"lang:default decode:true \" >\r\n[ec2-user]$ sudo yum install epel-release\r\n[ec2-user]$ sudo yum install fcgi spawn-fcgi fcgi-devel\r\n<\/pre>\n<p>GitHub\u304b\u3089fcgiwrap\u3092\u5165\u624b\u3057\u3066make\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\n[root src]# wget http:\/\/github.com\/gnosek\/fcgiwrap\/tarball\/master -O fcgiwrap.tar.gz\r\n[root src]# tar zxvf fcgiwrap.tar.gz\r\n[root src]# cd gnosek-fcgiwrap-*\r\n[root gnosek-fcgiwrap-99c942c]# autoreconf -i\r\n[root gnosek-fcgiwrap-99c942c]# .\/configure\r\n[root gnosek-fcgiwrap-99c942c]# make &amp;&amp; make install\r\ncc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3    fcgiwrap.c  -lfcgi  -o fcgiwrap\r\ninstall -d -m 755 \/usr\/local\/sbin\r\ninstall -m 755 fcgiwrap \/usr\/local\/sbin\r\ninstall -d -m 755 \/usr\/local\/man\/man8\r\ninstall -m 644 fcgiwrap.8 \/usr\/local\/man\/man8\r\n\r\n[root gnosek-fcgiwrap-99c942c]# echo $?\r\n0\r\n<\/pre>\n<p># autoreconf -i<br \/>\nbash: autoreconf: \u30b3\u30de\u30f3\u30c9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093<br \/>\n\u3068\u306a\u3063\u305f\u306e\u3067\u3001<br \/>\n# yum install autoconf autogen<br \/>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c<br \/>\n# autoreconf -i<br \/>\nCan&#8217;t exec &#8220;aclocal&#8221;: \u305d\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u3042\u308a\u307e\u305b\u3093<br \/>\n\u3068\u306a\u3063\u305f\u306e\u3067\u3001<br \/>\n# yum install libtool<br \/>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u5f8c<br \/>\n# autoreconf -i<\/p>\n<p><span id=\"S3\"><\/span><\/p>\n<h4>spawn-fcgi<\/h4>\n<p>fcgiwrap\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u305f\u306e\u3067spawn-fcgi\u3092\u8d77\u52d5\u3057\u3087\u3046\u3068\u3057\u305f\u304c\u8d77\u52d5\u3067\u304d\u306a\u3044\u3002:-)<\/p>\n<pre class=\"lang:default decode:true \" >[root gnosek-fcgiwrap-99c942c]# chkconfig spawn-fcgi on\r\n[root gnosek-fcgiwrap-99c942c]# \/etc\/rc.d\/init.d\/spawn-fcgi start\r\n[root gnosek-fcgiwrap-99c942c]# \/etc\/rc.d\/init.d\/spawn-fcgi status\r\nfcgiwrap \u306f\u505c\u6b62\u3057\u3066\u3044\u307e\u3059<\/pre>\n<p>\/etc\/init.d\/spawn-fcgi\u306e\u4fee\u6b63\u3002<br \/>\nfcgiwrap\u306f\u3001\/usr\/local\/sbin\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u305f\u3002<br \/>\nSOCKET=&#8221;\/var\/run\/fcgiwrap\/fcgiwrap.sock&#8221;\u306f\u3001\u5f8c\u8ff0\u3059\u308b\u3088\u3046\u306bfastcgi_pass 127.0.0.1:9001;\u3068\u3057\u305f\u306e\u3067\u4e0d\u8981\u304b\u306a\u3002<\/p>\n<pre class=\"lang:default decode:true \" >[root gnosek-fcgiwrap-99c942c]# vi \/etc\/init.d\/spawn-fcgi\r\n\r\n# Source function library.\r\n. \/etc\/rc.d\/init.d\/functions\r\n\r\nexec=\"\/usr\/bin\/spawn-fcgi\"\r\nprog=\"spawn-fcgi\"\r\nconfig=\"\/etc\/sysconfig\/spawn-fcgi\"\r\ncgi=\"\/usr\/local\/sbin\/fcgiwrap\"\r\n\r\npid=\"\/var\/run\/spawn-fcgi.pid\"\r\nSOCKET=\"\/var\/run\/fcgiwrap\/fcgiwrap.sock\"\r\n\r\n[ -e \/etc\/sysconfig\/$prog ] &amp;&amp; . \/etc\/sysconfig\/$prog\r\n\r\nlockfile=\/var\/lock\/subsys\/$prog\r\n\r\nstart() {\r\n    [ -x $exec ] || exit 5\r\n    [ -f $config ] || exit 6\r\n    echo -n $\"Starting $prog: \"\r\n    # Just in case this is left over with wrong ownership\r\n    [ -n \"${SOCKET}\" -a -S \"${SOCKET}\" ] &amp;&amp; rm -f ${SOCKET}\r\n    daemon \"$exec $OPTIONS &gt;\/dev\/null\"\r\n    retval=$?\r\n    echo\r\n    [ $retval -eq 0 ] &amp;&amp; touch $lockfile\r\n    return $retval\r\n}\r\n\r\nstop() {\r\n    echo -n $\"Stopping $prog: \"\r\n    killproc $prog\r\n    # Remove the socket in order to never leave it with wrong ownership\r\n    [ -n \"${SOCKET}\" -a -S \"${SOCKET}\" ] &amp;&amp; rm -f ${SOCKET}\r\n    retval=$?\r\n    echo\r\n    [ $retval -eq 0 ] &amp;&amp; rm -f $lockfile\r\n    return $retval\r\n}\r\n<\/pre>\n<p>\u3053\u3053\u3067\u3000\/etc\/sysconfig\/spawn-fcgi\u306bOPTIONS\u6307\u5b9a\u3002<\/p>\n<pre class=\"lang:default decode:true \" >OPTIONS=\"-u nginx -g nginx -a 127.0.0.1 -p 9001 -P \/var\/run\/spawn-fcgi.pid -- \/usr\/local\/sbin\/fcgiwrap\"\r\n<\/pre>\n<p>\u6b21\u306e\u8a2d\u5b9a\u65b9\u6cd5\u3082\u3042\u308b\u3088\u3046\u3060\u304cnginx\u306econf\u3082\u4fee\u6b63\u3057\u305f\u304c\u3046\u307e\u304f\u52d5\u4f5c\u3057\u306a\u304b\u3063\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\nOPTIONS=\"-u nginx -g nginx -S -s \/var\/run\/fcgiwrap\/fcgiwrap.sock -C 32 -F 1 -P \/var\/run\/spawn-fcgi.pid -- \/usr\/bin\/php-cgi\"\r\n<\/pre>\n<p><span id=\"S4\"><\/span><\/p>\n<h4>nginx\u306econf\u8a2d\u5b9a<\/h4>\n<p>OPTIONS\u6307\u5b9a\u306b\u5408\u308f\u305b\u3066127.0.0.1:9001\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \" >\r\nlocation ~ \\.cgi$ {\r\n    fastcgi_pass 127.0.0.1:9001;\r\n    fastcgi_index index.cgi;\r\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n    include \/etc\/nginx\/fastcgi_params;\r\n}<\/pre>\n<p>\u4e0a\u8a18\u8a2d\u5b9a\u3067spawn-fcgi\u3092\u8d77\u52d5\u3067\u304d\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true \" >[root gnosek-fcgiwrap-99c942c]# \/etc\/rc.d\/init.d\/spawn-fcgi start\r\nspawn-fcgi \u3092\u8d77\u52d5\u4e2d:                                       [  OK  ]\r\n<\/pre>\n<p>total0.cgi\u3092\u30b5\u30fc\u30d0\u30fc\u306b\u767b\u9332\u3002<\/p>\n<pre class=\"lang:default decode:true \" title=\"total0.cgi\">\r\n#!\/bin\/sh\r\n\r\ncat <<JSON_CONTENT\r\nContent-Type: application\/json\r\n\r\n{\"total\": 0}\r\nJSON_CONTENT\r\nexit 0\r\n<\/pre>\n<p><a  href=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2020\/04\/438ced633f28bef60e107f7b3bf85d8d.png\" data-rel=\"lightbox-gallery-0\" data-rl_title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2020-04-02 8.51.59\" data-rl_caption=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2020-04-02 8.51.59\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2020\/04\/438ced633f28bef60e107f7b3bf85d8d.png\" alt=\"\" width=\"346\" height=\"182\" class=\"alignnone size-full wp-image-3464\" srcset=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2020\/04\/438ced633f28bef60e107f7b3bf85d8d.png 346w, https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2020\/04\/438ced633f28bef60e107f7b3bf85d8d-300x158.png 300w\" sizes=\"(max-width: 346px) 100vw, 346px\" \/><\/a><br \/>\n\u53c2\u8003\uff1a<br \/>\n<a href=\"https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/examples\/fcgiwrap\/\">FCGI Wrap<\/a> \uff08Nginx\u30b5\u30a4\u30c8\u306e\u8a18\u4e8b\uff09<br \/>\n<a href=\"https:\/\/ac-5.net\/linux\/post-802\">Nginx\u3067CGI\/PERL\u3092\u52d5\u304b\u3059(FCGIWRAP+SPAWN-FCGI)<\/a>\uff082016\u5e74\uff09<br \/>\n<a href=\"https:\/\/qiita.com\/jey0taka\/items\/b961110a95d6edc2d870\">WordPress \u3092 Nginx + Fast-cgi \u3067\u52d5\u304b\u3059<\/a>(Qiita 2014\u5e74)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Views: 82AWS Linux2\u3067\u306f\u3001amazon-linux-extras \u3092\u4f7f\u7528\u3059\u308b\u3002 \u53c2\u8003\uff1a\u3010\u5165\u9580\u3011nginx \u3068\u306f \u8a2d\u5b9a\u65b9\u6cd5\u3092\u7d39\u4ecb $ sudo amazon-linux-extras install ng [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":3464,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/3460"}],"collection":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3460"}],"version-history":[{"count":16,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/3460\/revisions"}],"predecessor-version":[{"id":5974,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/3460\/revisions\/5974"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/media\/3464"}],"wp:attachment":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}