Serving WordPress with Caddy 2

Caddy config: /etc/caddy/Caddyfile

https://okz.io {
   ## ONLY use when you wish Caddy handle PHP request without Nginx 
   #root * /data/wwwroot/okz.io
   #php_fastcgi unix//dev/shm/php-cgi.sock

   encode zstd gzip

   ## Disable 

Nginx config

server {
  listen 8888;
  listen [::]:8888;  
  server_name okz.io;
  access_log off;
  index index.html index.htm index.php;
  root /data/wwwroot/okz.io;

include /usr/local/nginx/conf/rewrite/wordpress.conf;
  
location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    deny all;
  }
}

Fixing SSL error on WordPress

Add code below in to wp-config.php

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
  $_SERVER['HTTPS']='on';
}

if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  $_SERVER['HTTP_HOST'] =  $_SERVER['HTTP_X_FORWARDED_HOST'];
}

Source:
1. https://metalcoder.dev/how-to-get-wordpress-working-with-https-behind-a-reverse-proxy/
2. https://bensmann.no/caddy-server-wordpress/

Photo by Emilio Garcia on Unsplash