英文:
Caddy Server Certmagic - invalid memory address
问题
我正在尝试使用certmagic设置服务器,但每次运行代码时,我都只能得到下面的堆栈消息,无论我在网上查找的地方都说你只需要执行certmagic.HTTPS([]string{"my-domain.com"}, router)
,但这里肯定有些东西丢失了?
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6dd407]
goroutine 1 [running]:
go.uber.org/zap.(*Logger).check(0x0, 0xff, 0xc000026858, 0x11, 0xc000064f40)
/.../go/pkg/mod/go.uber.org/zap@v1.17.0/logger.go:265 +0x987
go.uber.org/zap.(*Logger).Debug(0x0, 0xc000026858, 0x11, 0xc000064f40, 0x1, 0x1)
/.../go/pkg/mod/go.uber.org/zap@v1.17.0/logger.go:180 +0x45
github.com/caddyserver/certmagic.(*Config).obtainCert.func2(0x8f2e70, 0xc0000240e0, 0x8f5370, 0xb14d30)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:511 +0x5c5
github.com/caddyserver/certmagic.(*Config).obtainCert(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0x873baf, 0x16, 0x1, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:566 +0x3a8
github.com/caddyserver/certmagic.(*Config).ObtainCertSync(...)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:421
github.com/caddyserver/certmagic.(*Config).manageOne.func1(0x842da0, 0xc000064400)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:334 +0x412
github.com/caddyserver/certmagic.(*Config).manageOne(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0x873baf, 0x16, 0x0, 0x0, 0x8f5370)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:361 +0x27b
github.com/caddyserver/certmagic.(*Config).manageAll(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0xc000020f60, 0x1, 0x1, 0xb45100, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:312 +0x1f1
github.com/caddyserver/certmagic.(*Config).ManageSync(...)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:251
github.com/caddyserver/certmagic.HTTPS(0xc000020f60, 0x1, 0x1, 0x8ec800, 0xc0000da0c0, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/certmagic.go:76 +0xdb
main.main()
/var/www/test/main.go:17 +0xe7
目前代码非常简单,只是从头开始了解它的工作原理,然后再扩展到其他项目中。
package main
import (
"github.com/caddyserver/certmagic"
"github.com/gorilla/mux"
"log"
"net/http"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello world"))
})
log.Fatal(certmagic.HTTPS([]string{"my-domain.com"}, router))
}
甚至更简单(certmagic提供的示例)也会得到相同的错误堆栈。
func main() {
handler := http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello world"))
})
certmagic.HTTPS([]string{"my-domain.com"}, handler)
}
英文:
I'm trying to setup a server using certmagic but every time I run the code I just get the below stack message, everywhere i have looked online says you just need to do certmagic.HTTPS([]string{"my-domain.com"}, router)
but there must be something missing here?
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6dd407]
goroutine 1 [running]:
go.uber.org/zap.(*Logger).check(0x0, 0xff, 0xc000026858, 0x11, 0xc000064f40)
/.../go/pkg/mod/go.uber.org/zap@v1.17.0/logger.go:265 +0x987
go.uber.org/zap.(*Logger).Debug(0x0, 0xc000026858, 0x11, 0xc000064f40, 0x1, 0x1)
/.../go/pkg/mod/go.uber.org/zap@v1.17.0/logger.go:180 +0x45
github.com/caddyserver/certmagic.(*Config).obtainCert.func2(0x8f2e70, 0xc0000240e0, 0x8f5370, 0xb14d30)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:511 +0x5c5
github.com/caddyserver/certmagic.(*Config).obtainCert(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0x873baf, 0x16, 0x1, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:566 +0x3a8
github.com/caddyserver/certmagic.(*Config).ObtainCertSync(...)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:421
github.com/caddyserver/certmagic.(*Config).manageOne.func1(0x842da0, 0xc000064400)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:334 +0x412
github.com/caddyserver/certmagic.(*Config).manageOne(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0x873baf, 0x16, 0x0, 0x0, 0x8f5370)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:361 +0x27b
github.com/caddyserver/certmagic.(*Config).manageAll(0xc0000952c0, 0x8f2e70, 0xc0000240e0, 0xc000020f60, 0x1, 0x1, 0xb45100, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:312 +0x1f1
github.com/caddyserver/certmagic.(*Config).ManageSync(...)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/config.go:251
github.com/caddyserver/certmagic.HTTPS(0xc000020f60, 0x1, 0x1, 0x8ec800, 0xc0000da0c0, 0x0, 0x0)
/.../go/pkg/mod/github.com/caddyserver/certmagic@v0.14.0/certmagic.go:76 +0xdb
main.main()
/var/www/test/main.go:17 +0xe7
The code is as bare minimum as it can be at the moment as just starting this from scratch to understand how it works before looking at expanding it to other projects
package main
import (
"github.com/caddyserver/certmagic"
"github.com/gorilla/mux"
"log"
"net/http"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello world"))
})
log.Fatal(certmagic.HTTPS([]string{"my-domain.com"}, router))
}
and even simpler (and an example provided on certmagic) gets the same error stack
func main() {
handler := http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello world"))
})
certmagic.HTTPS([]string{"my-domain.com"}, handler)
}
答案1
得分: 2
这是certmagic中已知的一个错误,已经修复并合并。
你可以在这里查看详细信息:https://github.com/caddyserver/certmagic/pull/135
他们似乎经常发布更新,所以你可以等几天来获取新的发布版本,或者在此期间使用主分支而不是v0.14.0。
英文:
This is a known bug in certmagic which has already been fixed and merged.
You can see the details here: https://github.com/caddyserver/certmagic/pull/135
They seem to release pretty often, so can either wait a few days for the new release, or use the main branch instead of v0.14.0, meanwhile.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论