{"id":4150,"date":"2022-07-31T23:07:14","date_gmt":"2022-07-31T14:07:14","guid":{"rendered":"https:\/\/tech.akat.info\/?p=4150"},"modified":"2022-07-31T23:07:14","modified_gmt":"2022-07-31T14:07:14","slug":"ubuntu-18-04-lts-go-nginx-%e7%92%b0%e5%a2%83%e3%82%92%e6%a7%8b%e7%af%89%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/tech.akat.info\/?p=4150","title":{"rendered":"Ubuntu 18.04 LTS + Go + Nginx \u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b"},"content":{"rendered":"<h2>Go\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/h2>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# cat \/etc\/lsb-release \r\nDISTRIB_ID=Ubuntu\r\nDISTRIB_RELEASE=18.04\r\nDISTRIB_CODENAME=bionic\r\nDISTRIB_DESCRIPTION=&quot;Ubuntu 18.04.6 LTS&quot;\r\n# whoami\r\nroot\r\n# cd \/usr\/local\/src\/\r\n# wget https:\/\/go.dev\/dl\/go1.18.4.linux-amd64.tar.gz\r\n# tar -C \/usr\/local -xzf go1.18.4.linux-amd64.tar.gz\r\n# echo 'export GOROOT=\/usr\/local\/go'   &gt;&gt; ~\/.profile\r\n# echo 'export PATH=$PATH:$GOROOT\/bin' &gt;&gt; ~\/.profile\r\n# source ~\/.profile\r\n# go version\r\ngo version go1.18.4 linux\/amd64\r\n<\/pre>\n<h2>systemd\u3078\u767b\u9332\u3057\u30669990\u30dd\u30fc\u30c8\u3067\u95b2\u89a7\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/h2>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# cd \/var\/www\/akat.info\/mgt\/htdocs\r\n# vi main.go\r\npackage main\r\n\r\nimport (\r\n    &quot;fmt&quot;\r\n    &quot;net\/http&quot;\r\n)\r\n\r\nfunc main() {\r\n    http.HandleFunc(&quot;\/&quot;, func(w http.ResponseWriter, r *http.Request) {\r\n        fmt.Fprintf(w, &quot;Hello World&quot;)\r\n    })\r\n\r\n    http.HandleFunc(&quot;\/greet\/&quot;, func(w http.ResponseWriter, r *http.Request) {\r\n        name := r.URL.Path&#x5B;len(&quot;\/greet\/&quot;):]\r\n        fmt.Fprintf(w, &quot;Hello %s\\n&quot;, name)\r\n    })\r\n\r\n    http.ListenAndServe(&quot;:9990&quot;, nil)\r\n}\r\n\r\n# go build main.go\r\n# vi \/lib\/systemd\/system\/goweb.service\r\n&#x5B;Unit]\r\nDescription=goweb\r\n\r\n&#x5B;Service]\r\nType=simple\r\nRestart=always\r\nRestartSec=5s\r\nExecStart=\/var\/www\/akat.info\/mgt\/htdocs\/main\r\n\r\n&#x5B;Install]\r\nWantedBy=multi-user.target\r\n\r\n# systemctl daemon-reload\r\n# systemctl start goweb\r\n# systemctl status goweb\r\n\u25cf goweb.service - goweb\r\n   Loaded: loaded (\/lib\/systemd\/system\/goweb.service; disabled; vendor preset: enabled)\r\n   Active: active (running) since Sun 2022-07-31 22:52:48 JST; 5s ago\r\n Main PID: 9045 (main)\r\n    Tasks: 4 (limit: 1152)\r\n   CGroup: \/system.slice\/goweb.service\r\n           \u2514\u25009045 \/var\/www\/akat.info\/mgt\/htdocs\/main\r\n\r\n 7\u6708 31 22:52:48 tech systemd&#x5B;1]: Started goweb.\r\n\r\n# curl http:\/\/localhost:9990\r\nHello World\r\n<\/pre>\n<h2>Nginx\u3068\u9023\u643a\u3055\u305b\u308b<\/h2>\n<p>Nginx\u306e\u8a2d\u5b9a\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u3066\u3001Nginx\u3092\u518d\u8d77\u52d5\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n...\r\n        location \/ {\r\n                proxy_set_header Host $http_host;\r\n                proxy_set_header X-Real-IP $remote_addr;\r\n                proxy_pass http:\/\/127.0.0.1:9990;\r\n                proxy_http_version 1.1;\r\n                proxy_set_header Upgrade $http_upgrade;\r\n                proxy_set_header Connection &quot;upgrade&quot;;\r\n                proxy_next_upstream error timeout http_502 http_503 http_504;\r\n        }\r\n...\r\n<\/pre>\n<p>\u95b2\u89a7\u3067\u304d\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u305f\uff01<br \/>\n<a href=\"https:\/\/tech.akat.info\/wp-content\/uploads\/2022\/07\/2022-07-31_225835.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tech.akat.info\/wp-content\/uploads\/2022\/07\/2022-07-31_225835-300x92.jpg\" alt=\"\" width=\"300\" height=\"92\" class=\"alignnone size-medium wp-image-4151\" srcset=\"https:\/\/tech.akat.info\/wp-content\/uploads\/2022\/07\/2022-07-31_225835-300x92.jpg 300w, https:\/\/tech.akat.info\/wp-content\/uploads\/2022\/07\/2022-07-31_225835-768x235.jpg 768w, https:\/\/tech.akat.info\/wp-content\/uploads\/2022\/07\/2022-07-31_225835.jpg 849w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>\u53c2\u8003<\/h2>\n<div class=\"oceanwp-oembed-wrap clr\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"CYtVdF7QL9\"><p><a href=\"https:\/\/sharoku-owl.com\/%e6%a2%9f%e3%81%ae%e5%b1%8b%e6%a0%b9%e8%a3%8f%e9%83%a8%e5%b1%8b-%e6%9c%80%e6%96%b0version%e3%81%aego%e3%82%92ubuntu%e3%81%ab%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b\/\">\u6700\u65b0Version\u306eGo\u3092Ubuntu\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;\u6700\u65b0Version\u306eGo\u3092Ubuntu\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b&#8221; &#8212; \u8eca\u516d\u306e\u689f\u306f\u98db\u3073\u307e\u308f\u308b\" src=\"https:\/\/sharoku-owl.com\/%e6%a2%9f%e3%81%ae%e5%b1%8b%e6%a0%b9%e8%a3%8f%e9%83%a8%e5%b1%8b-%e6%9c%80%e6%96%b0version%e3%81%aego%e3%82%92ubuntu%e3%81%ab%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b\/embed\/#?secret=7MlCidJU2Q#?secret=CYtVdF7QL9\" data-secret=\"CYtVdF7QL9\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/div>\n<p>https:\/\/quicknotepadtutorial.blogspot.com\/2019\/09\/how-to-setup-go-web-application-using.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b # cat \/etc\/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=18.04 DISTRIB_CODENAME=bionic DISTRIB_DES [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/4150"}],"collection":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4150"}],"version-history":[{"count":1,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/4150\/revisions"}],"predecessor-version":[{"id":4152,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/4150\/revisions\/4152"}],"wp:attachment":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}