• With issues:
  • Use the search tool before opening a new issue.
  • Please provide source code and commit sha if you found a bug.
  • Review existing issues and provide feedback or react to them.

Description

run autotls example1 got 404

How to reproduce

package main

import (
    "log"

    "github.com/gin-gonic/autotls"
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()

    // Ping handler
    r.GET("/ping", func(c *gin.Context) {
        c.String(200, "pong")
    })

    log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}

// curl https://example1.com/ping

Expectations

$ curl https://example1.com/ping
pong

Actual result

$ curl https://example1.com/ping
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title>404 Error</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="robots" content="noindex, nofollow">
  <style>
    @media screen and (max-width:500px) {
      body { font-size: .6em; } 
    }
  </style>
</head>

<body style="text-align: center;">

  <h1 style="font-family: Georgia, serif; color: #4a4a4a; margin-top: 4em; line-height: 1.5;">
    Sorry, this page doesn't exist.<br>Please check the URL or go back a page.
  </h1>

  <h2 style="  font-family: Verdana, sans-serif; color: #7d7d7d; font-weight: 300;">
    404 Error. Page Not Found.
  </h2>

</body>

</html>

Environment

  • go version: 1.19.5
  • gin version (or commit ref): v1.8.1
  • operating system: MACOS 13.1

Comment From: pscheid92

This is not a problem from gin or autotls.

When you call curl https://example1.com/ping you actually request the publicly hosted page https://example1.com/ping and not your locally running webserver.

You could tell curl to resolve exampl1.com to your local server, though:

curl -i --resolve example1.com:443:127.0.0.1 https://example1.com/ping

But this will result in an error:

2023/05/05 13:11:39 http: TLS handshake error from 127.0.0.1:59470: acme/autocert: unable to satisfy "https://acme-v02.api.letsencrypt.org/acme/authz-v3/225162221167" for domain "example1.com": no viable challenge type found

The reason is that your local machine is unreachable, for let's encrypt to perform the challenge. You should consult the let's encrypt documentation.