This setup will help you configure WordPress behind an Ingress Nginx in a Kubernetes cluster while using Cloudflare for SSL/TLS termination and security.
1. Set Home Page
Log in to your database, and update the wp_options
table:
mysql> UPDATE wp_options SET option_value = 'https://migrate.nicolas.io/' WHERE option_name IN ('siteurl', 'home');
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
2. WordPress Configuration
Add the following logic to your wp-config.php
file:
// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
//
if( strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false )
$_SERVER['HTTPS'] = 'on';
// (we include this by default because reverse proxying is extremely common in container environments)
3. Set Cloudflare SSL/TLS to Full/Strict
Navigate to your Cloudflare account and update your SSL/TLS settings.
4. Ingress Configuration
Create your Ingress configuration YAML file:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wordpress-migrate
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: 500m
nginx.ingress.kubernetes.io/proxy-read-timeout: 1000s
nginx.org/proxy-read-timeout: 1000s
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "X-Forwarded-Proto https";
spec:
rules:
- host: "migrate.nicolas.io"
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: wp-migrate
port:
number: 80
tls:
- hosts:
- migrate.nicolas.io
secretName: wildcard-nicolas-io
5. DNS Configuration
Finally, point your DNS to the IP address of your Ingress Nginx.