Two wordpress instances in different directories and same domain

1. The problem I’m having:

I am migrating from shared Apache web server to VPS Caddy server.
On my former server I was running two separate Wordpress instances. Each running in a folder. The folder structure was:

https://example.com/spanish
https://example.com/english

So based on the Accept-Language var, the root .htaccess ( https://example.com) chose where to take the user. If language was Spanish (ie. es-ES), then the user was redirected to https://example.com/spanish. If not Spanish, then it takes him to the default https://example.com/english

I used .htaccess files to achieve that in the old hosting. One in the root path, another in the /spanish path and another one in the /english .

Here is the content of those .htaccess files:
[1] PrivateBin

So I am trying to replicate the config into Caddy with no luck. Even though I managed to make the redirect apparently fine. But the way is processing it when is gets to the proper directory does not seem to be ok as I get a 500 error.

The Wordpress instances have both set the siteurl and home as below (same as it used to be in the former hosting):

siteurl: https://example.com/english
home: https://example.com/english

siteurl: https://example.com/spanish
home: https://example.com/spanish

2. Error messages and/or full log output:

* Request completely sent off
< HTTP/1.1 500 Internal Server Error
< Alt-Svc: h3=":443"; ma=2592000
< Content-Type: text/html; charset=UTF-8
< Server: Caddy
< Status: 500 Internal Server Error

3. Caddy version:

v2.8.4

4. How I installed and ran Caddy:

a. System environment:

VPS - Debian 11 bullseye

d. My complete Caddy config:

example.com {
        # Set the root directory
        root * /var/www/mainsite

        # Redirect to /spanish if Accept-Language header starts with 'es' and URL doesn't start with /spanish or /english
        @redirectToSpanish {
                not path /spanish* /english*
                header_regexp Accept-Language ^es
        }
        redir @redirectToSpanish /spanish{uri} 301

        # Redirect to /english if URL doesn't start with /spanish or /english
        @redirectToEnglish {
                not path /spanish* /english*
        }
        redir @redirectToEnglish/english{uri} 301

        # Handle requests to /spanish
        handle_path /spanish* {
                root * /var/www/mainsite/spanish
                php_fastcgi unix//run/php/php7.4-fpm.sock
                file_server
        }

        # Handle requests to /english
        handle_path /english* {
                root * /var/www/mainsite/english
                php_fastcgi unix//run/php/php7.4-fpm.sock
                file_server
        }
}

5. Links to relevant resources:

What’s in your Caddy logs though?

1 Like

I note a few things:

  • You’ve got canonical site URLs in WordPress that include the language URI prefix.
  • You’re using handle_path which strips the prefix before routing the request.
  • You’re using root * /var/www/mainsite/<language> to establish which site files should be served.

This strikes me as a little odd. WordPress expects the prefix, but you’re taking it out.

Kinda like saying to WordPress, no, the client didn’t actually request either of your sites, but serve/process the files from the English site, just trust me. (Or Spanish).

I don’t know if it’s the cause of your issues, but it seems incongruent. I wonder if handle_path is actually the behaviour you want or if you just want handle.

I think your config could be written tremendously more efficiently.

example.com {
  @language path /spanish* /english*
  handle @language {
    root * /var/www/mainsite
    php_fastcgi unix//run/php/php7.4-fpm.sock {
      # Override try_files to keep the root index file boxed in
      try_files {path} {path}/index.php {path.0}/index.php
    }
    file_server
  }

  handle {
    @spanish header Accept-Language es*
    redir @spanish /spanish{uri}
    redir /english{uri}
  }
}
2 Likes

Thanks both for your quick replies.

@Whitestrake I barely have experience with Caddy. This is actually my first time playing around with it so sorry if the previous code did not make much sense.
So I updated Caddyfile with your code. However, I keep getting error 500 from Wordpress.

I debugged & got this log:
10:52 → English browser
10:53 → Spanish browser

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.5530617,"logger":"events","msg":"event","name":"tls_get_certificate","id":"0dc2aa9c-6f8a-44c3-8da0-7400d17df7a9","origin":"tls","data":{"client_hello":{"CipherSuites":[39578,4865,4866,4867,49195,49199,49196,49200,52393,52392,49171,49172,156,157,47,53],"ServerName":"example.com","SupportedCurves":[31354,25497,29,23,24],"SupportedPoints":"AA==","SignatureSchemes":[1027,2052,1025,1283,2053,1281,2054,1537],"SupportedProtos":["h2","http/1.1"],"SupportedVersions":[56026,772,771],"RemoteAddr":{"IP":"185.40.40.40","Port":16378,"Zone":""},"LocalAddr":{"IP":"185.130.45.208","Port":443,"Zone":""}}}}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.5531778,"logger":"tls.handshake","msg":"choosing certificate","identifier":"example.com","num_choices":1}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.5532138,"logger":"tls.handshake","msg":"default certificate selection results","identifier":"example.com","subjects":["example.com"],"managed":true,"issuer_key":"acme-v02.api.letsencrypt.org-directory","hash":"9d35f5be3653753a2eb527d9ce46ee70ce1a7c013ddc7ec9381719cd9214cf15"}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.5532317,"logger":"tls.handshake","msg":"matched certificate in cache","remote_ip":"185.40.40.40","remote_port":"16378","subjects":["example.com"],"managed":true,"expiration":1735331521,"hash":"9d35f5be3653753a2eb527d9ce46ee70ce1a7c013ddc7ec9381719cd9214cf15"}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.6703682,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"185.40.40.40","remote_port":"16378","client_ip":"185.40.40.40","proto":"HTTP/2.0","method":"GET","host":"example.com","uri":"/english/","headers":{"Pragma":["no-cache"],"Sec-Ch-Ua-Mobile":["?0"],"Cookie":["REDACTED"],"Priority":["u=0, i"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Accept-Language":["en,es;q=0.9,en-US;q=0.8"],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Windows\""],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"method":"GET","uri":"/english/index.php"}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.6704671,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"/run/php/php7.4-fpm.sock","total_upstreams":1}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.6707563,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_ip":"185.40.40.40","remote_port":"16378","client_ip":"185.40.40.40","proto":"HTTP/2.0","method":"GET","host":"example.com","uri":"/english/index.php","headers":{"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Sec-Ch-Ua-Mobile":["?0"],"Cookie":["REDACTED"],"Sec-Fetch-Site":["none"],"X-Forwarded-For":["185.40.40.40"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Pragma":["no-cache"],"Accept-Language":["en,es;q=0.9,en-US;q=0.8"],"Priority":["u=0, i"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["example.com"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"env":{"DOCUMENT_URI":"/english/index.php","HTTP_SEC_CH_UA":"\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"","HTTP_SEC_CH_UA_PLATFORM":"\"Windows\"","HTTP_USER_AGENT":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","REQUEST_SCHEME":"https","SCRIPT_FILENAME":"/var/www/mainsite/english/index.php","HTTP_COOKIE":"","HTTP_SEC_CH_UA_MOBILE":"?0","HTTP_ACCEPT_ENCODING":"gzip, deflate, br, zstd","HTTP_X_FORWARDED_HOST":"example.com","CONTENT_LENGTH":"","REMOTE_HOST":"185.40.40.40","REMOTE_USER":"","SERVER_PROTOCOL":"HTTP/2.0","HTTP_SEC_FETCH_USER":"?1","CONTENT_TYPE":"","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_SEC_FETCH_MODE":"navigate","AUTH_TYPE":"","REQUEST_URI":"/english/","SERVER_PORT":"443","HTTP_CACHE_CONTROL":"no-cache","HTTP_X_FORWARDED_FOR":"185.40.40.40","REMOTE_IDENT":"","QUERY_STRING":"","REMOTE_ADDR":"185.40.40.40","HTTPS":"on","HTTP_SEC_FETCH_SITE":"none","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7","HTTP_PRAGMA":"no-cache","GATEWAY_INTERFACE":"CGI/1.1","REQUEST_METHOD":"GET","HTTP_HOST":"example.com","SCRIPT_NAME":"/english/index.php","SSL_PROTOCOL":"TLSv1.3","HTTP_PRIORITY":"u=0, i","HTTP_SEC_FETCH_DEST":"document","HTTP_ACCEPT_LANGUAGE":"en,es;q=0.9,en-US;q=0.8","HTTP_X_FORWARDED_PROTO":"https","PATH_INFO":"","REMOTE_PORT":"16378","SERVER_NAME":"example.com","SERVER_SOFTWARE":"Caddy/v2.8.4","DOCUMENT_ROOT":"/var/www/mainsite"},"dial":"/run/php/php7.4-fpm.sock","env":{"SERVER_SOFTWARE":"Caddy/v2.8.4","DOCUMENT_ROOT":"/var/www/mainsite","HTTP_SEC_FETCH_DEST":"document","HTTP_ACCEPT_LANGUAGE":"en,es;q=0.9,en-US;q=0.8","HTTP_X_FORWARDED_PROTO":"https","PATH_INFO":"","REMOTE_PORT":"16378","SERVER_NAME":"example.com","HTTP_USER_AGENT":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","DOCUMENT_URI":"/english/index.php","HTTP_SEC_CH_UA":"\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"","HTTP_SEC_CH_UA_PLATFORM":"\"Windows\"","HTTP_SEC_CH_UA_MOBILE":"?0","REQUEST_SCHEME":"https","SCRIPT_FILENAME":"/var/www/mainsite/english/index.php","HTTP_COOKIE":"","SERVER_PROTOCOL":"HTTP/2.0","HTTP_SEC_FETCH_USER":"?1","HTTP_ACCEPT_ENCODING":"gzip, deflate, br, zstd","HTTP_X_FORWARDED_HOST":"example.com","CONTENT_LENGTH":"","REMOTE_HOST":"185.40.40.40","REMOTE_USER":"","CONTENT_TYPE":"","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_SEC_FETCH_MODE":"navigate","HTTP_CACHE_CONTROL":"no-cache","AUTH_TYPE":"","REQUEST_URI":"/english/","SERVER_PORT":"443","HTTPS":"on","HTTP_SEC_FETCH_SITE":"none","HTTP_X_FORWARDED_FOR":"185.40.40.40","REMOTE_IDENT":"","QUERY_STRING":"","REMOTE_ADDR":"185.40.40.40","SCRIPT_NAME":"/english/index.php","SSL_PROTOCOL":"TLSv1.3","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7","HTTP_PRAGMA":"no-cache","GATEWAY_INTERFACE":"CGI/1.1","REQUEST_METHOD":"GET","HTTP_HOST":"example.com","HTTP_PRIORITY":"u=0, i"},"request":{"remote_ip":"185.40.40.40","remote_port":"16378","client_ip":"185.40.40.40","proto":"HTTP/2.0","method":"GET","host":"example.com","uri":"/english/index.php","headers":{"X-Forwarded-Host":["example.com"],"Priority":["u=0, i"],"X-Forwarded-Proto":["https"],"Upgrade-Insecure-Requests":["1"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Cache-Control":["no-cache"],"Sec-Ch-Ua-Mobile":["?0"],"Cookie":["REDACTED"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Pragma":["no-cache"],"Accept-Language":["en,es;q=0.9,en-US;q=0.8"],"Sec-Fetch-Site":["none"],"X-Forwarded-For":["185.40.40.40"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}}}

Sep 30 10:52:18 exampleserver caddy[69635]: {"level":"debug","ts":1727693538.6735842,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"unix//run/php/php7.4-fpm.sock","duration":0.002980656,"request":{"remote_ip":"185.40.40.40","remote_port":"16378","client_ip":"185.40.40.40","proto":"HTTP/2.0","method":"GET","host":"example.com","uri":"/english/index.php","headers":{"Accept-Language":["en,es;q=0.9,en-US;q=0.8"],"Sec-Fetch-Site":["none"],"X-Forwarded-For":["185.40.40.40"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Pragma":["no-cache"],"Priority":["u=0, i"],"X-Forwarded-Proto":["https"],"X-Forwarded-Host":["example.com"],"Sec-Ch-Ua":["\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Cookie":["REDACTED"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Sec-Ch-Ua-Mobile":["?0"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"example.com"}},"headers":{"Status":["500 Internal Server Error"],"Content-Type":["text/html; charset=UTF-8"]},"status":500}


Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.372326,"logger":"events","msg":"event","name":"tls_get_certificate","id":"285a203a-6f43-43d0-94df-29a3bf2ba7fe","origin":"tls","data":{"client_hello":{"CipherSuites":[4865,4866,4867],"ServerName":"example.com","SupportedCurves":[25497,29,23,24],"SupportedPoints":null,"SignatureSchemes":[1027,2052,1025,1283,2053,1281,2054,1537,513],"SupportedProtos":["h3"],"SupportedVersions":[772],"RemoteAddr":{"IP":"185.40.40.40","Port":56144,"Zone":""},"LocalAddr":{"IP":"185.130.45.208","Port":443,"Zone":""}}}}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.3724651,"logger":"tls.handshake","msg":"choosing certificate","identifier":"example.com","num_choices":1}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.3725145,"logger":"tls.handshake","msg":"default certificate selection results","identifier":"example.com","subjects":["example.com"],"managed":true,"issuer_key":"acme-v02.api.letsencrypt.org-directory","hash":"9d35f5be3653753a2eb527d9ce46ee70ce1a7c013ddc7ec9381719cd9214cf15"}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.3725333,"logger":"tls.handshake","msg":"matched certificate in cache","remote_ip":"185.40.40.40","remote_port":"56144","subjects":["example.com"],"managed":true,"expiration":1735331521,"hash":"9d35f5be3653753a2eb527d9ce46ee70ce1a7c013ddc7ec9381719cd9214cf15"}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.4932623,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_ip":"185.40.40.40","remote_port":"56144","client_ip":"185.40.40.40","proto":"HTTP/3.0","method":"GET","host":"example.com","uri":"/spanish/","headers":{"Pragma":["no-cache"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Windows\""],"Cache-Control":["no-cache"],"Sec-Fetch-User":["?1"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Gpc":["1"],"Accept-Language":["es-ES,es;q=0.6"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Priority":["u=0, i"],"Upgrade-Insecure-Requests":["1"],"Sec-Ch-Ua":["\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h3","server_name":"example.com"}},"method":"GET","uri":"/spanish/index.php"}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.4933908,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"/run/php/php7.4-fpm.sock","total_upstreams":1}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.4937983,"logger":"http.reverse_proxy.transport.fastcgi","msg":"roundtrip","request":{"remote_ip":"185.40.40.40","remote_port":"56144","client_ip":"185.40.40.40","proto":"HTTP/3.0","method":"GET","host":"example.com","uri":"/spanish/index.php","headers":{"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Mobile":["?0"],"Priority":["u=0, i"],"Sec-Fetch-Site":["none"],"Sec-Gpc":["1"],"Accept-Language":["es-ES,es;q=0.6"],"Sec-Ch-Ua":["\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Forwarded-For":["185.40.40.40"],"X-Forwarded-Proto":["https"],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"X-Forwarded-Host":["example.com"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Pragma":["no-cache"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h3","server_name":"example.com"}},"env":{"REMOTE_IDENT":"","DOCUMENT_ROOT":"/var/www/mainsite","SCRIPT_FILENAME":"/var/www/mainsite/spanish/index.php","HTTP_PRAGMA":"no-cache","HTTP_SEC_FETCH_DEST":"document","HTTP_X_FORWARDED_HOST":"example.com","HTTP_SEC_CH_UA":"\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"","REMOTE_HOST":"185.40.40.40","REMOTE_PORT":"56144","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","HTTP_SEC_FETCH_USER":"?1","HTTP_SEC_FETCH_MODE":"navigate","HTTP_ACCEPT_LANGUAGE":"es-ES,es;q=0.6","HTTP_X_FORWARDED_PROTO":"https","HTTP_HOST":"example.com","REQUEST_URI":"/spanish/","HTTP_PRIORITY":"u=0, i","HTTP_SEC_FETCH_SITE":"none","HTTP_ACCEPT_ENCODING":"gzip, deflate, br, zstd","HTTP_SEC_GPC":"1","CONTENT_TYPE":"","PATH_INFO":"","REMOTE_ADDR":"185.40.40.40","DOCUMENT_URI":"/spanish/index.php","SERVER_SOFTWARE":"Caddy/v2.8.4","HTTPS":"on","HTTP_CACHE_CONTROL":"no-cache","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8","GATEWAY_INTERFACE":"CGI/1.1","REMOTE_USER":"","REQUEST_SCHEME":"https","SERVER_NAME":"example.com","HTTP_USER_AGENT":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","CONTENT_LENGTH":"","QUERY_STRING":"","SERVER_PROTOCOL":"HTTP/3.0","SERVER_PORT":"443","AUTH_TYPE":"","REQUEST_METHOD":"GET","SSL_PROTOCOL":"TLSv1.3","HTTP_X_FORWARDED_FOR":"185.40.40.40","SCRIPT_NAME":"/spanish/index.php","HTTP_SEC_CH_UA_MOBILE":"?0","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_SEC_CH_UA_PLATFORM":"\"Windows\""},"dial":"/run/php/php7.4-fpm.sock","env":{"HTTP_CACHE_CONTROL":"no-cache","HTTP_ACCEPT":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8","GATEWAY_INTERFACE":"CGI/1.1","REMOTE_USER":"","REQUEST_SCHEME":"https","SERVER_NAME":"example.com","SERVER_SOFTWARE":"Caddy/v2.8.4","HTTPS":"on","CONTENT_LENGTH":"","QUERY_STRING":"","SERVER_PROTOCOL":"HTTP/3.0","SERVER_PORT":"443","HTTP_USER_AGENT":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36","AUTH_TYPE":"","REQUEST_METHOD":"GET","SSL_PROTOCOL":"TLSv1.3","SCRIPT_NAME":"/spanish/index.php","HTTP_SEC_CH_UA_MOBILE":"?0","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_SEC_CH_UA_PLATFORM":"\"Windows\"","HTTP_X_FORWARDED_FOR":"185.40.40.40","REMOTE_IDENT":"","DOCUMENT_ROOT":"/var/www/mainsite","SCRIPT_FILENAME":"/var/www/mainsite/spanish/index.php","HTTP_X_FORWARDED_HOST":"example.com","HTTP_SEC_CH_UA":"\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"","REMOTE_HOST":"185.40.40.40","REMOTE_PORT":"56144","SSL_CIPHER":"TLS_AES_128_GCM_SHA256","HTTP_SEC_FETCH_USER":"?1","HTTP_PRAGMA":"no-cache","HTTP_SEC_FETCH_DEST":"document","HTTP_X_FORWARDED_PROTO":"https","HTTP_HOST":"example.com","REQUEST_URI":"/spanish/","HTTP_PRIORITY":"u=0, i","HTTP_SEC_FETCH_SITE":"none","HTTP_SEC_FETCH_MODE":"navigate","HTTP_ACCEPT_LANGUAGE":"es-ES,es;q=0.6","CONTENT_TYPE":"","PATH_INFO":"","REMOTE_ADDR":"185.40.40.40","DOCUMENT_URI":"/spanish/index.php","HTTP_ACCEPT_ENCODING":"gzip, deflate, br, zstd","HTTP_SEC_GPC":"1"},"request":{"remote_ip":"185.40.40.40","remote_port":"56144","client_ip":"185.40.40.40","proto":"HTTP/3.0","method":"GET","host":"example.com","uri":"/spanish/index.php","headers":{"Sec-Gpc":["1"],"Accept-Language":["es-ES,es;q=0.6"],"Sec-Ch-Ua":["\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"X-Forwarded-Proto":["https"],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Forwarded-For":["185.40.40.40"],"X-Forwarded-Host":["example.com"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Pragma":["no-cache"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Mobile":["?0"],"Priority":["u=0, i"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h3","server_name":"example.com"}}}

Sep 30 10:53:02 exampleserver caddy[69635]: {"level":"debug","ts":1727693582.4968894,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"unix//run/php/php7.4-fpm.sock","duration":0.003412965,"request":{"remote_ip":"185.40.40.40","remote_port":"56144","client_ip":"185.40.40.40","proto":"HTTP/3.0","method":"GET","host":"example.com","uri":"/spanish/index.php","headers":{"Sec-Ch-Ua":["\"Brave\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\""],"Sec-Gpc":["1"],"Accept-Language":["es-ES,es;q=0.6"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"],"Sec-Ch-Ua-Platform":["\"Windows\""],"X-Forwarded-For":["185.40.40.40"],"X-Forwarded-Proto":["https"],"Cache-Control":["no-cache"],"Upgrade-Insecure-Requests":["1"],"Pragma":["no-cache"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"],"Sec-Fetch-Dest":["document"],"X-Forwarded-Host":["example.com"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br, zstd"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"],"Sec-Ch-Ua-Mobile":["?0"],"Priority":["u=0, i"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h3","server_name":"example.com"}},"headers":{"Status":["500 Internal Server Error"],"Content-Type":["text/html; charset=UTF-8"]},"status":500}


Is there anything else I could try?

Thanks

You can add the capture_stderr option to php_fastcgi to hopefully get logs about the PHP error.

2 Likes

@francislavoie Thank you. capture_stderr showed the issue (the Wordfence plugin)

@Whitestrake thanks so much for the code, it just works great.

3 Likes