WordPress + Docker Double Caching with Redis and Nginx Reverse Proxy

While WordPress is great it’s slow and taxing on a webserver. However ultimately Redis’ object cache and the related plugin as well as Nginx’s reverse proxy caching make for an especially fast site. Combine Traefik for management and do it all on Docker for an excellent solution.

Step 1: Create a basic Traefik folder (for this example in your home directory ~/Traefik

Step 2: in the new Traefik directory, create a conf directory and create the acme.json.

mkdir ./conf
sudo touch ./conf/acme.json
sudo chmod 0600 ./conf/acme.json

Step 3: Load the docker-compose.yml into the top Traefik directory as follows:

---
version: '3.8'
services:
  traefik:
    container_name: traefik
    image: traefik:chevrotin
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./conf/traefik.toml:/etc/traefik/traefik.toml:ro
      - ./conf/traefik_dynamic.toml:/etc/traefik/traefik_dynamic.toml:ro
      - ./conf/acme.json:/acme.json
    labels:
      traefik.enable: true
      traefik.http.routers.api-http.rule: Host(`traefik.${HOSTNAME1}`)
      traefik.http.routers.api-http.entrypoints: web
      traefik.http.routers.api-http.middlewares: https-redirect@file
      traefik.http.routers.api-https.service: api@internal
      traefik.http.routers.api-https.rule: Host(`traefik.${HOSTNAME1}`)
      traefik.http.routers.api-https.entrypoints: websecure
      traefik.http.routers.api-https.middlewares: security@file, compression@file, https-redirect@file, auth
      traefik.http.routers.api-https.tls: true
      traefik.http.routers.api-https.tls.certresolver: letsencrypt
      traefik.http.middlewares.auth.basicauth.users: "username:httpasswd_double_$$"

  sqlwp:
    container_name: sqlwp
    image: mariadb:latest
    restart: unless-stopped
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
    labels:
      traefik.enable: false

  nginxwp-1:
    container_name: nginxforwp-${HOST1}
    image: nginx:stable-alpine
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./wordpress-${HOST1}:/var/www/html
      - ${LOGS_LOCAL}:/var/log/nginx/
      - ./conf/nginx-${HOST1}:/etc/nginx/
      - nginxcache:/var/www/html/cache
    links:
      - wp-1
    labels:
      traefik.enable: true
      traefik.http.routers.nginxwp-${HOST1}-http.rule: Host(`${HOSTNAME1}`)||Host(`www.${HOSTNAME1}`)
      traefik.http.routers.nginxwp-${HOST1}-http.entrypoints: web
      traefik.http.routers.nginxwp-${HOST1}-http.middlewares: https-redirect@file
      traefik.http.routers.nginxwp-${HOST1}-https.rule: Host(`${HOSTNAME1}`)||Host(`www.${HOSTNAME1}`)
      traefik.http.routers.nginxwp-${HOST1}-https.entrypoints: websecure
      traefik.http.routers.nginxwp-${HOST1}-https.middlewares: security@file, compression@file, https-redirect@file
      traefik.http.routers.nginxwp-${HOST1}-https.tls: true
      traefik.http.routers.nginxwp-${HOST1}-https.tls.certresolver: letsencrypt

  wp-1:
    container_name: wpapp-${HOST1}
    image: wordpress:php7.4-fpm-alpine
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./wordpress-${HOST1}:/var/www/html
      - ./conf/php.ini:/usr/local/etc/php/php.ini
      - nginxcache:/var/www/html/cache
    depends_on:
      - sqlwp
    environment:
      - WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST}
      - WORDPRESS_DB_USER=${WORDPRESS_DB_USER}
      - WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
      - WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}
      - WORDPRESS_TABLE_PREFIX=${HOST1}
    labels:
      traefik.enable: false

volumes:
  dataredis:
  nginxcache:

Step 4: Create a .env file in the main Traefik directory

MYSQL_ROOT_PASSWORD=make_a_good_password
MYSQL_USER=something_but_admin_or_root
MYSQL_PASSWORD=make_a_good_password
MYSQL_DATABASE=wpdb
WORDPRESS_DB_USER=something_but_admin_or_root
WORDPRESS_DB_PASSWORD=make_a_good_other_password
WORDPRESS_DB_HOST=sqlwp
WORDPRESS_DB_NAME=wpdb
HOST1=mydomain
HOSTNAME1=mydomain.com

Follow the rest of the directions here:

https://computerz.solutions/docker-compose-wordpress-nginx-et-traefik/

Fixing Vodafone UK London Underground wifi

If you’re using an iPhone and have a Vodafone UK monthly subscription, there’s a special wireless network SSID (VodafoneWiFi) that bypasses the annoying Virgin Media login screen everytime you’re in the London Underground (as with the SSID VirginMediaWifi).

Unfortunately there’s some sort of Apple issue that doesn’t let it connect directly as it asks for a username and password instead of using the SIM authentication (EAP-SIM). This config profile forces the iPhone to use the SIM to connect itself to VodafoneWiFi. Enjoy. Click here from your mobile browser and hit Install

UPDATE for 2020 – still works on the tube, though a little unreliable on newest iOS 13 as maybe 20% of the time it will refuse to connect. I suspect that’s an access point problem vs a phone problem. Either way this is as good as it gets!

Amazon Echo in the UK

No longer needed now that Amazon launched Echo here officially. Although I get better results by keeping a US model and just updating the address, so technically it’s a US model in the UK. You lose specific UK recipes for now but certain things like iHeartRadio only work on the US model. YMMV.

Devdiner has a great write up on how to quickly hack your Echo to work outside the US. For those in the UK it works perfectly once you get the address properly formatted including County. Weather and even the Uber booking seem to work flawlessly. Here’s the UK specific code I used. Follow his directions for the cURL method and replace the XXXXX’es with whatever is already there in your own settings.

{"devicePreferences":[{"deviceAccountId":"xxxxxxxxxx","deviceAddress":"10 High Street, London, London, GB","deviceAddressModel":{"city":"London","countryCode":"GB","county":"London","district":null,"houseNumber":"10","label":null,"postalCode":"WC1A 1AA","state":"London","street":"High Street"},"deviceSerialNumber":"xxxxxxx","deviceType":"xxxxxxx","firstRunCompleted":true,"notificationEarconEnabled":true,"postalCode":"WC1A 1AA","responseStyle":"CONCISE","searchCustomerId":"xxxxxxxx","temperatureScale":"FAHRENHEIT","timeZoneId":"Europe/London"}]}