Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

http and https on the same server

I'm wondering if I can have HTTP and HTTPS routes working on the same server. I have a Caddy server that needs to hit the /caddy/ask/ endpoint on the server to check if SSL certificate should be allowed for the subdomains. It works well; except when the certificate of the main domain expires. Then it enters chicken-egg problem and there's no way out.

I've been suggested to use a HTTP endpoint for Caddy's ask_endpoint to avoid this issue. I am wondering if I can access say http://localhost/caddy/ask on my server while the rest of the site functions on https://mydomain.com.

0 likes
7 replies
enoch91's avatar

@thebigk Yes it's possible to have both HTTP and HTTPS working, here are the steps to follow,

  • Set Up HTTPS for Your Main Domain
mydomain.com {
    tls {
        # Your TLS/SSL certificate configurations
    }
    # Other configurations for your main domain
}

  • Add a separate block in your Caddyfile to handle HTTP traffic for the /caddy/ask endpoint. You can specify a different port for HTTP if needed.
http://localhost:8080 {
    # Other configurations for HTTP requests
}

In your Caddy configuration or wherever you specify the ask endpoint, use the HTTP version for the /caddy/ask endpoint.

ask http://localhost:8080/caddy/ask

This way, Caddy will communicate with the HTTP endpoint http://localhost:8080/caddy/ask when checking SSL certificate renewals.

Then, restart Caddy

thebigk's avatar
Level 13

Thank you, @enoch91 . The ask_endpoint needs to respond 200 for allowed subdomains. That is, Caddy will make a get request to the ask_endpoint. I need to handle that inside Laravel.

If I configure this block:

http://localhost:8080 {
    # Other configurations for HTTP requests
}

What will be the corresponding entry in my Laravel routes file? Will it be able to invoke a controller on localhost/caddy/ask route?

enoch91's avatar

@thebigk configure your Caddy server to point to the correct Laravel installation and to listen on the appropriate port (in this case, http://localhost:8080). Also, make sure your Laravel development server is running.

define a corresponding route in your Laravel routes file

Route::get('/caddy/ask', 'CaddyController@handleAskEndpoint');
class CaddyController extends Controller
{
    public function handleAskEndpoint()
    {
        // Handle the ask endpoint logic here
        // Respond with a 200 status for allowed subdomains
        return response()->json(['status' => 'allowed'], 200);
    }
}
thebigk's avatar
Level 13

@enoch91 - I am looking to run in this on the production server. So far, I've added the following block:-

:5001 {
        root * /home/forge/jatra.club/public
        php_fastcgi unix//run/php/php8.2-fpm.sock
}

The ask endpoint has been updated to: ask http://localhost:5001/caddy/ask

The logs show that -

jatra.club: certificate not allowed by ask endpoint http://localhost:5001/caddy/ask - non-2xx status code 404

I tried executing from the terminal for my server -

curl -v localhost:5001/caddy/ask?domain=jatra.club

..and it throws a 404 response html. The controller is programmed to respond with 200 response for the domain jatra.club

enoch91's avatar
enoch91
Best Answer
Level 2

@thebigk Update the configuration like this:

:5001 {
    root * /home/forge/jatra.club/public
    php_fastcgi unix//run/php/php8.2-fpm.sock

    log stdout

    ask http://localhost:5001/caddy/ask?domain=jatra.club
    
}

Examine the Laravel logs (storage/logs/laravel.log) for any error messages or stack traces related to the request. This might provide more information about why Laravel is responding with a 404.

1 like

Please or to participate in this conversation.