第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

自己的 https certbot web 服務(wù)器返回 404 頁面未找到

自己的 https certbot web 服務(wù)器返回 404 頁面未找到

Go
楊魅力 2023-05-15 10:17:59
我有一個(gè)非常簡(jiǎn)單的go https 網(wǎng)絡(luò)服務(wù)器這是代碼:package mainimport (    // "fmt"    // "io"    "net/http"    "log")func HelloServer(w http.ResponseWriter, req *http.Request) {    w.Header().Set("Content-Type", "text/plain")    w.Write([]byte("This is an example server.\n"))    // fmt.Fprintf(w, "This is an example server.\n")    // io.WriteString(w, "This is an example server.\n")}func main() {    http.HandleFunc("/hello", HelloServer)    err := http.ListenAndServeTLS(":8085", "fullchain.pem", "privkey.pem", nil)//    err := http.ListenAndServeTLS(":8085", "certificate_ca.crt", "certificate.csr", nil)    if err != nil {        log.Fatal("ListenAndServe: ", err)    }}它偵聽由防火墻打開的端口 8085。我使用 certbot 生成的 SSL 證書:sudo certbot certonly --standalone -d example.com所以我使用以下生成的文件構(gòu)建了 Web 服務(wù)器:err := http.ListenAndServeTLS(":8085", "fullchain.pem", "privkey.pem", nil)這是港口狀態(tài):$ sudo netstat -tulpn | grep 8085tcp6       0      0 :::8085                 :::*                    LISTEN      23429/hello$ sudo ufw status | grep 80858085/tcp                   ALLOW       Anywhere8085/tcp (v6)              ALLOW       Anywhere (v6)所以當(dāng)我嘗試從另一臺(tái)機(jī)器:$ curl -sL https://example.com:8085404 page not found在 DigitalOcean 上運(yùn)行的 Web 服務(wù)器。我需要以某種方式配置我的 Droplet 嗎?不確定我錯(cuò)過了什么?我還有certificate.crt, certificate_ca.crt, certificate.csr從賣給我域名的公司那里得到的文件。我應(yīng)該以某種方式使用這些文件嗎?我需要這個(gè)用于 OAuth 重定向 URI。
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊

您已經(jīng)為 URL 路徑配置了處理程序/hello,但還沒有為路徑配置處理程序/。因此,當(dāng)您嘗試加載該路徑時(shí),您會(huì)得到 404。


如果您嘗試加載,https://example.com:8085/hello那么您會(huì)看到示例文本。


您還可以為 設(shè)置路線/,例如:


 http.HandleFunc("/", HelloServer)

請(qǐng)注意,因?yàn)檫@會(huì)匹配所有可能的 URL,所以如果您只想匹配主頁,則需要明確檢查 URL,例如:


    if req.URL.Path != "/" {

        http.NotFound(w, req)

        return

    }

您還應(yīng)該考慮使用更靈活的多路復(fù)用器,例如 gorilla/mux。


查看完整回答
反對(duì) 回復(fù) 2023-05-15
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)