How can I define multiple hostname on local for PHP development purpose?

I’m trying to run caddy web server v2 for PHP development, How would I define multiple hostnames for local?

I tried to give random name in Caddyfile
When I tried to start.
I’m getting following error

➜  caddy git:(master) ✗ 2020/05/08 22:08:59 [INFO][testhost.com] Waiting on rate limiter...
2020/05/08 22:08:59 [INFO][testhost.com] Done waiting
2020/05/08 22:08:59 [INFO] [testhost.com] acme: Obtaining bundled SAN certificate given a CSR
2020/05/08 22:09:01 [INFO] [testhost.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451512286
2020/05/08 22:09:01 [INFO] [testhost.com] acme: Could not find solver for: tls-alpn-01
2020/05/08 22:09:01 [INFO] [testhost.com] acme: use http-01 solver
2020/05/08 22:09:01 [INFO] [testhost.com] acme: Trying to solve HTTP-01
2020/05/08 22:09:06 [INFO] Deactivating auth: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451512286
2020/05/08 22:09:06 [INFO] Unable to deactivate the authorization: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451512286
2020/05/08 22:09:06 [ERROR] error: one or more domains had a problem:
[testhost.com] acme: error: 400 :: urn:ietf:params:acme:error:dns :: DNS problem: SERVFAIL looking up A for testhost.com - the domain's nameservers may be malfunctioning, url: 
 (challenge=http-01 remaining=[tls-alpn-01])
2020/05/08 22:09:08 [INFO] [testhost.com] acme: Obtaining bundled SAN certificate given a CSR
2020/05/08 22:09:09 [INFO] [testhost.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451515366
2020/05/08 22:09:09 [INFO] [testhost.com] acme: use tls-alpn-01 solver
2020/05/08 22:09:09 [INFO] [testhost.com] acme: Trying to solve TLS-ALPN-01
2020/05/08 22:09:18 [INFO] Deactivating auth: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451515366
2020/05/08 22:09:19 [INFO] Unable to deactivate the authorization: https://acme-v02.api.letsencrypt.org/acme/authz-v3/4451515366
2020/05/08 22:09:19 [ERROR] error: one or more domains had a problem:
[testhost.com] acme: error: 400 :: urn:ietf:params:acme:error:dns :: DNS problem: SERVFAIL looking up A for testhost.com - the domain's nameservers may be malfunctioning, url: 
 (challenge=tls-alpn-01 remaining=[])
2020/05/08 22:09:21 [ERROR] attempt 1: [testhost.com] Obtain: [testhost.com] error: one or more domains had a problem:
[testhost.com] acme: error: 400 :: urn:ietf:params:acme:error:dns :: DNS problem: SERVFAIL looking up A for testhost.com - the domain's nameservers may be malfunctioning, url: 
 - retrying in 1m0s (22.809746938s/720h0m0s elapsed)...

Hi @itsursujit - thanks for bringing your question here from GitHub.

Can you please edit your post and fill out the template? There’s not enough information here for us to be helpful to you.

Where can I find the template?

your caddyfile.

When you go to create a new topic and choose the Help category, the template auto-fills into the textbox. Filling out a post without the template means that you deleted it first :slightly_frowning_face:

As @tweeniev2 said, we’ll need your Caddyfile and some other information too. The template will make sure we get most of the basics covered.

Caddyfile has only one line and that is testhost.com

Well, I guess that is enough to know a problem then. Do you own testhost.com?

Please read how automatic HTTPS works: Automatic HTTPS — Caddy Documentation

And try the quick start: HTTPS quick-start — Caddy Documentation

You need to use a real domain name that you control.

Actually not, As I mentioned on title, I’m trying to create virtual host with multiple names on local for PHP Development purpose, I was trying with any arbitrary name to see how it works and get myself started with CaddyServer

for development purposes either you need a domain to use https or just go with php built-in server or non tls. then for production use php_fastcgi directive.

i basically got 1 domain, i create a subdomain and use it in caddy.

So like Apache or Nginx, I can’t create virtual host and use HTTPS on CaddyServer? Or am I missing something?

you can create anything in caddy but https working with valid domains.

1 Like

for example

domain.com {
php_fastcgi unix://php_sock
}

sub.domain.com {
php_fastcgi unix://php_sock
}

domain2.com {
php_fastcgi unix://php_sock
}
1 Like

Let me ask one more question if you don’t mind,

Say, I’ve a microservice in PHP that only accepts HTTPS and runs on HTTPS only.
Using nginx/apache I can create virtual host name and add https. For e.g. random.site and add https with local generated SSL Keys and everything works fine…

Please let me know if it’s possible with Caddy Server as well. If yes, then how would I do that?

well we are using caddy because you don’t need to do that config.

in your Caddyfile (equivalent is nginx.conf or default)

yourdomain.com {
 php_fastcgi unix//run/php/php7.4-fpm.sock
 file_server
}

done. you got https running on yourdomain.com

everything can be configured in same file. you don’t need sites-available sites-enabled etc.

I’m sorry if my question was not clear at first :slight_smile:
I agree with how Caddy Server works. Also I found that I can work with any public domains as you’ve mentioned above.
Just wondering if it’s possible to setup https for non-public domain like random localhost names: abc.xys. with Caddy

it’s very extreme use case, as who needs https in development environment.

There are cases when application needs to be tested and running on https on development environment.

I’ve same scenario/use case where one of the service needs to https connection for it’s working.

Not extreme use case really, HTTPS default is the way of the internet, so to replicate production usage, it is common sense to replicate HTTPS usage on dev environment too.

If the domain names used aren’t valid domains and only for local dev testing, you can override both server and your PC’s DNS using /etc/hosts file on server and equivalent on your PC depending on OS. That is what I did at Caddy V2 tls internal only work when port 80/443 are free? just needed help with the internal SSL cert setup routine by setting http_port and htps_port for local SSL certs on ports other than 80/443 for my usage on domains on port 81/4444.

So for my virtualbox install, for invalid domains used for local testing, I edited my server’s /etc/hosts and my Windows 10 pc’s C:\Windows\System32\drivers\etc\hosts

192.168.0.18 ngx.domain.com
192.168.0.18 caddy.domain.com
curl -I http://caddy.domain.com:81/caddy-index.html
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 12226
Content-Type: text/html; charset=utf-8
Etag: "q9xapl9fm"
Last-Modified: Wed, 06 May 2020 18:44:09 GMT
Server: Caddy
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Powered-By: caddy centminmod
X-Xss-Protection: 1; mode=block
Date: Fri, 08 May 2020 17:25:52 GMT
curl -Ik https://caddy.domain.com:4444/caddy-index.html
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 12226
Content-Type: text/html; charset=utf-8
Etag: "q9xapl9fm"
Last-Modified: Wed, 06 May 2020 18:44:09 GMT
Server: Caddy
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Powered-By: caddy centminmod
X-Xss-Protection: 1; mode=block
Date: Fri, 08 May 2020 17:26:08 GMT
3 Likes

As @eva2000 has said, it’s not an extreme usecase. Caddy supports HTTPS in development using tls internal. See the docs:

2 Likes