{"id":332408,"date":"2022-04-26T03:00:13","date_gmt":"2022-04-26T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=332408"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=332408","title":{"rendered":"<span>HTTPs-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u043c Let&#8217;s Encrypt \u043d\u0430 Go<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Go, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 HTTP \u0441\u0435\u0440\u0432\u0435\u0440. \u041a \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043f\u043e HTTPS. \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 <a href=\"https:\/\/linux.die.net\/man\/8\/pound\" rel=\"noopener noreferrer nofollow\"><u>Pound<\/u><\/a> &#8212; HTTP\/HTTPS reverse-proxy and load-balancer \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. TLS \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438\u0437\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/letsencrypt.org\/\" rel=\"noopener noreferrer nofollow\"><u>Let&#8217;s Encrypt<\/u><\/a>.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430. \u041f\u0440\u0430\u0432\u0434\u0430, \u0447\u0430\u0449\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 <a href=\"https:\/\/www.nginx.com\/\" rel=\"noopener noreferrer nofollow\"><u>Nginx<\/u><\/a>, \u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 Pound, \u0430 \u043d\u0435 Nginx. \u0412\u0441\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043d\u0430 Go \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u0438\u043a\u0430 \u0441 \u043f\u044f\u0442\u044c-\u0448\u0435\u0441\u0442\u044c\u044e \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u043c\u0438 \u043d\u0430 <a href=\"https:\/\/www.ansible.com\/\" rel=\"noopener noreferrer nofollow\"><u>Ansible<\/u><\/a>, \u0437\u0430\u043a\u0430\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0434\u0435\u043f\u043b\u043e\u0439 \u0438 \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0441\u043b\u0430\u0432\u043d\u043e \u0443\u043b\u0435\u0433\u043b\u043e\u0441\u044c \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u043a\u0435. <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c94\/b76\/fea\/c94b76feacbc54fd4ad4d00c7670d562.jpg\" alt=\"HTTP \u043d\u0430 Go + Pound \u0438\u043b\u0438 Nginx + TLS with Let's Encrypt\" title=\"HTTP \u043d\u0430 Go + Pound \u0438\u043b\u0438 Nginx + TLS with Let's Encrypt\" width=\"450\" height=\"281\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c94\/b76\/fea\/c94b76feacbc54fd4ad4d00c7670d562.jpg\" data-blurred=\"true\"\/><figcaption>HTTP \u043d\u0430 Go + Pound \u0438\u043b\u0438 Nginx + TLS with Let&#8217;s Encrypt<\/figcaption><\/figure>\n<p>\u042f \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c, \u0432 \u0441\u0432\u043e\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0438\u0441\u0430\u043b \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Assembly_language\" rel=\"noopener noreferrer nofollow\"><u>Assembler<\/u><\/a>-\u0435. \u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u041a\u0431 \u0441\u0447\u0438\u0442\u0430\u043b\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c. \u0412\u0438\u0434\u0438\u043c\u043e \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u0432\u043e \u043c\u043d\u0435 \u0437\u0430\u0441\u0442\u0440\u044f\u043b\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0436\u0435\u043b\u0435\u0437\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0445 \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u0422\u0430\u043a \u0436\u0435 \u044f \u043d\u0438 \u043a\u0430\u043a \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0432\u044b\u043a\u043d\u0443\u0442\u044c \u043a \u044d\u0442\u0438\u043c \u0436\u0443\u0442\u043a\u0438\u043c \u043f\u0430\u043f\u043a\u0430\u043c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u2018node_modules\u2019 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0443 \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435.<\/p>\n<p>\u0418 \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f&#8230; <br \/>\u0417\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043d\u0430\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u00abHTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u043c Let&#8217;s Encrypt \u043d\u0430 Go\u00bb. \u0413\u043e\u0434 \u0434\u0443\u043c\u0430\u043b. \u0428\u0443\u0447\u0443. \u041c\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u0438\u043a\u0430\u043c\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0433\u043e\u0434, \u0438 \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0418 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c. \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0435\u0441\u0442\u044c \u0432 <a href=\"https:\/\/pkg.go.dev\/golang.org\/x\" rel=\"noopener noreferrer nofollow\"><u>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Go<\/u><\/a><u>.<\/u> \u0418\u0442\u0430\u043a, \u0432\u043e\u0442 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 Go \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTPS \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0441\u044f TLS \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043f\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 Let\u2019s Encrypt:<\/p>\n<pre><code class=\"go\">mux := http.NewServeMux() mux.HandleFunc(\"\/\", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, \"Hello, TLS user! Your config: %+v\", r.TLS) }) log.Fatal(http.Serve(autocert.NewListener(domain), mux))<\/code><\/pre>\n<p>\u0418 \u0432\u0441\u0435! \u0414\u0430, \u0438 \u0432\u0441\u0435 &#8212; \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f HTTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0418\u0449\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u0430 \u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u044e \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440&#8230;<br \/>\u041d\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u043e! &#8212; \u2018autocert.NewListener(domain)\u2019 \u0432 \u2018http.Serve\u2019.<\/p>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u0438 \u043d\u0430 \u0445\u043e\u0441\u0442\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u0435\u043b\u044b\u0439 IP \u0430\u0434\u0440\u0435\u0441. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e Let\u2019s Encrypt \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u044f \u0441 HTTP \u043d\u0430 HTTPS, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"go\">go func() { if err := http.ListenAndServe(\":80\", http.HandlerFunc(redirectTLS)); err != nil { log.Fatalf(\"ListenAndServe error: %v\", err) } }()<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d HTTP \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 80-\u043c \u043f\u043e\u0440\u0442\u0443 \u0438 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439 \u0432\u0441\u0435 \u043d\u0430 \u043d\u0430\u0448 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2018redirectTLS\u2019:<\/p>\n<pre><code class=\"go\">func redirectTLS(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, \"https:\/\/\"+domain+\":443\"+r.RequestURI, http.StatusMovedPermanently) }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#8216;\u2013domain&#8217; \u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">sudo go run . -domain=example.com<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e. \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d \u0438 \u0431\u0435\u043b\u044b\u0439 IP \u0430\u0434\u0440\u0435\u0441.<\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0430 \u043d\u0430\u00a0<a href=\"https:\/\/github.com\/\" rel=\"noopener noreferrer nofollow\">Github<\/a>:<br \/><a href=\"https:\/\/github.com\/kirill-scherba\/https-example\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/kirill-scherba\/https-example<\/a><\/p>\n<p>\u0412\u043e\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0430\u0434\u0440\u0435\u0441 \u043d\u0430\u00a0<a href=\"https:\/\/gitflic.ru\/\" rel=\"noopener noreferrer nofollow\">Gitflic<\/a>, \u043f\u043e\u043a\u0430 \u043e\u043d \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439:<br \/><a href=\"https:\/\/gitflic.ru\/project\/kirill-scherba\/github-backup\" rel=\"noopener noreferrer nofollow\">https:\/\/gitflic.ru\/project\/kirill-scherba\/<\/a><a href=\"https:\/\/github.com\/kirill-scherba\/https-example\" rel=\"noopener noreferrer nofollow\">https-example<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/662940\/\"> https:\/\/habr.com\/ru\/post\/662940\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Go, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 HTTP \u0441\u0435\u0440\u0432\u0435\u0440. \u041a \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043f\u043e HTTPS. \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 <a href=\"https:\/\/linux.die.net\/man\/8\/pound\" rel=\"noopener noreferrer nofollow\"><u>Pound<\/u><\/a> &#8212; HTTP\/HTTPS reverse-proxy and load-balancer \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. TLS \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438\u0437\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/letsencrypt.org\/\" rel=\"noopener noreferrer nofollow\"><u>Let&#8217;s Encrypt<\/u><\/a>.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430. \u041f\u0440\u0430\u0432\u0434\u0430, \u0447\u0430\u0449\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 <a href=\"https:\/\/www.nginx.com\/\" rel=\"noopener noreferrer nofollow\"><u>Nginx<\/u><\/a>, \u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 Pound, \u0430 \u043d\u0435 Nginx. \u0412\u0441\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043d\u0430 Go \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u0438\u043a\u0430 \u0441 \u043f\u044f\u0442\u044c-\u0448\u0435\u0441\u0442\u044c\u044e \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u043c\u0438 \u043d\u0430 <a href=\"https:\/\/www.ansible.com\/\" rel=\"noopener noreferrer nofollow\"><u>Ansible<\/u><\/a>, \u0437\u0430\u043a\u0430\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0434\u0435\u043f\u043b\u043e\u0439 \u0438 \u0440\u0430\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0441\u043b\u0430\u0432\u043d\u043e \u0443\u043b\u0435\u0433\u043b\u043e\u0441\u044c \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u043a\u0435. <\/p>\n<figure class=\"\"><figcaption>HTTP \u043d\u0430 Go + Pound \u0438\u043b\u0438 Nginx + TLS with Let&#8217;s Encrypt<\/figcaption><\/figure>\n<p>\u042f \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c, \u0432 \u0441\u0432\u043e\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0438\u0441\u0430\u043b \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Assembly_language\" rel=\"noopener noreferrer nofollow\"><u>Assembler<\/u><\/a>-\u0435. \u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u0442\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u041a\u0431 \u0441\u0447\u0438\u0442\u0430\u043b\u0441\u044f \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c. \u0412\u0438\u0434\u0438\u043c\u043e \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u0432\u043e \u043c\u043d\u0435 \u0437\u0430\u0441\u0442\u0440\u044f\u043b\u043e \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0436\u0435\u043b\u0435\u0437\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0445 \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u0422\u0430\u043a \u0436\u0435 \u044f \u043d\u0438 \u043a\u0430\u043a \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0432\u044b\u043a\u043d\u0443\u0442\u044c \u043a \u044d\u0442\u0438\u043c \u0436\u0443\u0442\u043a\u0438\u043c \u043f\u0430\u043f\u043a\u0430\u043c \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u2018node_modules\u2019 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0443 \u0441\u0442\u0435\u0440\u0435\u0442\u044c \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435.<\/p>\n<p>\u0418 \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f&#8230; <br \/>\u0417\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043d\u0430\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u00abHTTP-\u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u043c Let&#8217;s Encrypt \u043d\u0430 Go\u00bb. \u0413\u043e\u0434 \u0434\u0443\u043c\u0430\u043b. \u0428\u0443\u0447\u0443. \u041c\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0434\u0438\u043d\u043e\u0437\u0430\u0432\u0440\u0438\u043a\u0430\u043c\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0433\u043e\u0434, \u0438 \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0418 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c. \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438, \u0435\u0441\u0442\u044c \u0432 <a href=\"https:\/\/pkg.go.dev\/golang.org\/x\" rel=\"noopener noreferrer nofollow\"><u>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 Go<\/u><\/a><u>.<\/u> \u0418\u0442\u0430\u043a, \u0432\u043e\u0442 \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430 Go \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTPS \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0441\u044f TLS \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043f\u043e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 Let\u2019s Encrypt:<\/p>\n<pre><code class=\"go\">mux := http.NewServeMux() mux.HandleFunc(\"\/\", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, \"Hello, TLS user! Your config: %+v\", r.TLS) }) log.Fatal(http.Serve(autocert.NewListener(domain), mux))<\/code><\/pre>\n<p>\u0418 \u0432\u0441\u0435! \u0414\u0430, \u0438 \u0432\u0441\u0435 &#8212; \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f HTTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0418\u0449\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f, \u0430 \u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u044e \u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440&#8230;<br \/>\u041d\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u043e! &#8212; \u2018autocert.NewListener(domain)\u2019 \u0432 \u2018http.Serve\u2019.<\/p>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0435 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u0438 \u043d\u0430 \u0445\u043e\u0441\u0442\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0431\u0435\u043b\u044b\u0439 IP \u0430\u0434\u0440\u0435\u0441. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e Let\u2019s Encrypt \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0430\u044f \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0430\u0434\u0440\u0435\u0441\u0430\u0446\u0438\u044f \u0441 HTTP \u043d\u0430 HTTPS, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"go\">go func() { if err := http.ListenAndServe(\":80\", http.HandlerFunc(redirectTLS)); err != nil { log.Fatalf(\"ListenAndServe error: %v\", err) } }()<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d HTTP \u0441\u0435\u0440\u0432\u0435\u0440, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 80-\u043c \u043f\u043e\u0440\u0442\u0443 \u0438 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0439 \u0432\u0441\u0435 \u043d\u0430 \u043d\u0430\u0448 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2018redirectTLS\u2019:<\/p>\n<pre><code class=\"go\">func redirectTLS(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, \"https:\/\/\"+domain+\":443\"+r.RequestURI, http.StatusMovedPermanently) }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 &#8216;\u2013domain&#8217; \u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"bash\">sudo go run . -domain=example.com<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e. \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0443 \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d \u0438 \u0431\u0435\u043b\u044b\u0439 IP \u0430\u0434\u0440\u0435\u0441.<\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0430 \u043d\u0430\u00a0<a href=\"https:\/\/github.com\/\" rel=\"noopener noreferrer nofollow\">Github<\/a>:<br \/><a href=\"https:\/\/github.com\/kirill-scherba\/https-example\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/kirill-scherba\/https-example<\/a><\/p>\n<p>\u0412\u043e\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0430\u0434\u0440\u0435\u0441 \u043d\u0430\u00a0<a href=\"https:\/\/gitflic.ru\/\" rel=\"noopener noreferrer nofollow\">Gitflic<\/a>, \u043f\u043e\u043a\u0430 \u043e\u043d \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439:<br \/><a href=\"https:\/\/gitflic.ru\/project\/kirill-scherba\/github-backup\" rel=\"noopener noreferrer nofollow\">https:\/\/gitflic.ru\/project\/kirill-scherba\/<\/a><a href=\"https:\/\/github.com\/kirill-scherba\/https-example\" rel=\"noopener noreferrer nofollow\">https-example<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/662940\/\"> https:\/\/habr.com\/ru\/post\/662940\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-332408","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332408"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332408\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}