Randomly gets http error 500 on working pages

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

Downloaded and started with sudo apt install caddy
system service, Caddyfile imports poul.dev which looks like this.

a. System environment:

Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-66-generic x86_64)
Digital Ocean Droplet, 1GB Ram, 25GB SSD.

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

Caddyfile

import poul.dev

poul.dev

poul.dev {

root * /home/poul/www/poul.dev/public
log {
	output file /home/poul/logs/access.log
}
file_server
php_fastcgi unix//run/php/php7.2-fpm.php.sock php
}

3. The problem I’m having:

randomly get http error 500 every 3-4th time i load a page.

4. Error messages and/or full log output:

Chrome

poul.dev is currently unable to handle this request.

HTTP ERROR 500

caddy access log

{
	"level": "error",
	"ts": 1590567671.7840648,
	"logger": "http.log.access.log0",
	"msg": "handled request",
	"request": {
		"method": "GET",
		"uri": "/test.php",
		"proto": "HTTP/2.0",
		"remote_addr": "152.115.132.234:54561",
		"host": "poul.dev",
		"headers": {
			"Sec-Fetch-Mode": ["navigate"],
			"Sec-Fetch-Dest": ["document"],
			"Pragma": ["no-cache"],
			"Cache-Control": ["no-cache"],
			"Upgrade-Insecure-Requests": ["1"],
			"Sec-Fetch-Site": ["cross-site"],
			"Accept-Language": ["en-US,en;q=0.9,da;q=0.8"],
			"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"],
			"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"],
			"Sec-Fetch-User": ["?1"],
			"Accept-Encoding": ["gzip, deflate, br"]
		},
		"tls": {
			"resumed": false,
			"version": 772,
			"ciphersuite": 4865,
			"proto": "h2",
			"proto_mutual": true,
			"server_name": "poul.dev"
		}
	},
	"common_log": "152.115.132.234 - - [27/May/2020:08:21:11 +0000] \"GET /test.php HTTP/2.0\" 500 0",
	"duration": 0.000150363,
	"size": 0,
	"status": 500,
	"resp_headers": {
		"Server": ["Caddy"]
	}
}

5. What I already tried:

Made a symfony project, created test.html and test.php (with phpinfo()).
Tried refreshing all files in Chrome, only php files are giving http error 500 randomly.
also tried with curl and here the php files also randomly gives http error 500.

curl -v --http2 https://poul.dev/test.php
*   Trying 127.0.1.1...
* TCP_NODELAY set
* Connected to poul.dev (127.0.1.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Unknown (8):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Client hello (1):
* TLSv1.3 (OUT), TLS Unknown, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=poul.dev
*  start date: May 26 11:11:17 2020 GMT
*  expire date: Aug 24 11:11:17 2020 GMT
*  subjectAltName: host "poul.dev" matched cert's "poul.dev"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* Using Stream ID: 1 (easy handle 0x562b149c7580)
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
> GET /test.php HTTP/2
> Host: poul.dev
> User-Agent: curl/7.58.0
> Accept: */*
> 
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
< HTTP/2 500 
< server: Caddy
< content-length: 0
< date: Wed, 27 May 2020 09:02:57 GMT
< 
* Connection #0 to host poul.dev left intact

6. Links to relevant resources:

https://poul.dev ?

Caddy v2 no longer has a php preset for fastcgi, it’s now part of the php_fastcgi directive. Caddy is parsing php as a 2nd upstream, so it’s trying to load balance requests between your unix socket and another upstream called php, which doesn’t exist. Just remove php from the end of that line :smile:

1 Like

Ahhh great xD Thanks a bunch, worked!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.