{"id":2430,"date":"2023-08-29T14:34:33","date_gmt":"2023-08-29T05:34:33","guid":{"rendered":"https:\/\/weblog.hirohiro716.com\/?p=2430"},"modified":"2023-09-18T12:00:09","modified_gmt":"2023-09-18T03:00:09","slug":"ec2%e3%82%92nginx%ef%bc%8bnode-js%e3%81%a7web%e3%82%b5%e3%83%bc%e3%83%90%e3%83%bc%e3%81%ab%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/weblog.hirohiro716.com\/?p=2430","title":{"rendered":"EC2\u3092Nginx\uff0bnode.js\u3067WEB\u30b5\u30fc\u30d0\u30fc\u306b\u3059\u308b"},"content":{"rendered":"<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">\r\n\u30fb \u30c7\u30a3\u30b9\u30c8\u30ea\u30d3\u30e5\u30fc\u30b7\u30e7\u30f3: Amazon Linux 2023.1.20230825\r\n\u30fb \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30bf\u30a4\u30d7: t3a.nano\r\n\u30fb \u30dc\u30ea\u30e5\u30fc\u30e0\u30b5\u30a4\u30ba: 20GB\r\n<\/pre>\n<p>\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u65e5\u672c\u306b\u5909\u66f4\u3059\u308b\u3002<br \/>\n\u203b\u4f7f\u7528\u3067\u304d\u308b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306flist-timezones\u30b5\u30d6\u30b3\u30de\u30f3\u30c9\u3067\u78ba\u8a8d\u3067\u304d\u308b<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# timedatectl set-timezone Asia\/Tokyo\r\n<\/pre>\n<p>\u30e1\u30e2\u30ea\u304c512MB\u3057\u304b\u306a\u3044\u306e\u3067\u30b9\u30ef\u30c3\u30d7\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n\u203b\u4e8b\u524d\u306bswapon &#8211;summary\u3067\u65e2\u5b58\u30b9\u30ef\u30c3\u30d7\u3092\u78ba\u8a8d\u6e08\u307f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# dd if=\/dev\/zero of=\/swapfile bs=1M count=1024\r\n# mkswap \/swapfile\r\n# swapon \/swapfile\r\n<\/pre>\n<p>fstab\u306e\u672b\u5c3e\u306b\u3082\u8a2d\u5b9a\u30921\u884c\u8ffd\u52a0\u3057\u3066\u6c38\u7d9a\u5316\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: \/etc\/fstab; notranslate\" title=\"\/etc\/fstab\">\r\n\/swapfile    none    swap    sw    0    0\r\n<\/pre>\n<p>nvm\u3092\u4f7f\u7528\u3057\u3066node.js\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<br \/>\n\u203b\u4f7f\u7528\u3067\u304d\u308bnode.js\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306fnvm ls-remote\u3067\u78ba\u8a8d\u3067\u304d\u308b<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# dnf install git\r\n$ git clone https:\/\/github.com\/creationix\/nvm.git ~\/temp-nvm\r\n$ ~\/temp-nvm\/install.sh\r\n$ rm -r ~\/temp-nvm\/\r\n$ source ~\/.bashrc\r\n$ nvm install --lts\r\n<\/pre>\n<p>\u9069\u5f53\u306aWEB\u30b5\u30fc\u30d0\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ~\/testapp.js; notranslate\" title=\"~\/testapp.js\">\r\nconst http = require(&quot;http&quot;);\r\nhttp.createServer(function(request, response) {\r\n    response.writeHead(200, {&quot;Content-Type&quot;: &quot;text\/plain&quot;});\r\n    response.end(&quot;Hello, World!\\n&quot;);\r\n}).listen(3000);\r\n<\/pre>\n<p>node.js\u3067WEB\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ node ~\/testapp.js\r\n<\/pre>\n<p>Nginx\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u8d77\u52d5\uff0b\u6709\u52b9\u5316\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# dnf install nginx\r\n# systemctl enable --now nginx\r\n<\/pre>\n<p>\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3092\u8a2d\u5b9a\u3057\u3066node.js\u306eWEB\u30b5\u30fc\u30d0\u30fc\u306b\u4e2d\u7d99\u3059\u308b\u3002<br \/>\n\u203b\u300cclient_max_body_size 10m\u300d\u306710MB\u307e\u3067\u306e\u753b\u50cf\u306a\u3069\u3082\u53d7\u3051\u53d6\u308c\u308b<br \/>\n\u203b\u300cproxy_set_header Host $host\u300d\u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u9001\u4fe1\u3057\u305f\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u30db\u30b9\u30c8\u540d\u3092\u6e21\u3059<br \/>\n\u203b\u300cproxy_set_header X-Real-IP $remote_addr\u300d\u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092\u6e21\u3059<\/p>\n<pre class=\"brush: plain; title: \/etc\/nginx\/conf.d\/node.js.conf; notranslate\" title=\"\/etc\/nginx\/conf.d\/node.js.conf\">\r\nserver {\r\n    listen 80;\r\n    listen &#x5B;::]:80;\r\n    server_name testapp.example.com;\r\n    client_max_body_size 10m;\r\n    location \/ {\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_path http:\/\/localhost:3000\/;\r\n    }\r\n}\r\n<\/pre>\n<p>Nginx\u306e\u8a2d\u5b9a\u5024\u3092\u518d\u8aad\u8fbc\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl reload nginx\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30fb \u30c7\u30a3\u30b9\u30c8\u30ea\u30d3\u30e5\u30fc\u30b7\u30e7\u30f3: Amazon Linux 2023.1.20230825 \u30fb \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30bf\u30a4\u30d7: t3a.nano \u30fb \u30dc\u30ea\u30e5\u30fc\u30e0\u30b5\u30a4\u30ba: 20GB \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u65e5\u672c\u306b\u5909\u66f4\u3059\u308b\u3002 \u203b\u4f7f\u7528\u3067\u304d\u308b\u30bf\u30a4\u30e0\u30be\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-2430","post","type-post","status-publish","format-standard","hentry","category-aws"],"views":979,"_links":{"self":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2430"}],"version-history":[{"count":10,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2430\/revisions"}],"predecessor-version":[{"id":2441,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2430\/revisions\/2441"}],"wp:attachment":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}