GolangNote

Golang笔记

Golang 实现的 Let’s Encrypt 验证响应handler

Permalink

简单的web 服务,响应Let’s Encrypt 域名所有者验证,不用 nginx 大器

Go: 响应Let’s Encrypt 域名所有者验证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
	"flag"
	"log"
	"net/http"
)

func main() {
	var dir = flag.String("dir", ".", "folder")
	var port = flag.String("p", "80", "port")

	flag.Parse()

	log.Println("dir : ", *dir)
	log.Println("port : ", *port)

	staticHandler := http.StripPrefix("/.well-known/acme-challenge/", http.FileServer(http.Dir(*dir)))
	http.Handle("/.well-known/acme-challenge/", staticHandler)
	srv := &http.Server{Addr: ":" + *port}

	log.Fatal(srv.ListenAndServe())
}

本文网址: https://golangnote.com/topic/221.html 转摘请注明来源

Related articles

Golang 单实例实现网站多域名请求

有时候写网站,为了统一的后端,把不同业务都集中到一个后端,这时就需要处理多域名的请求,在 Go http server 里实现很简单,只需把不同域名映射到不同的 `http.Handler`。...

Write a Comment to "Golang 实现的 Let’s Encrypt 验证响应handler"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.17.1 Processed in 0ms