Files
news-platform/wordpress/docker-compose.yml
T
Artur Moreira eee991400e fix(wordpress): wp-admin redirect behind NPM (BIT-470)
Preserve X-Forwarded-Proto from the edge proxy in CT nginx so WordPress
sees HTTPS. When WORDPRESS_PUBLIC_URL still defaults to localhost:8080,
derive WP_HOME/WP_SITEURL from Host and forwarded headers for proxied
requests (X-Forwarded-For present). Document behaviour in deployment and
wordpress README.

Made-with: Cursor
2026-03-24 18:53:25 +00:00

91 lines
3.5 KiB
YAML

services:
db:
image: mariadb:11
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 8
start_period: 90s
wordpress:
image: wordpress:6-php8.3-apache
restart: unless-stopped
depends_on:
db:
condition: service_healthy
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_TABLE_PREFIX: wp_
# Browser-facing URL (must match how users open the site). Required when Nginx proxies
# /wp-admin/ on https://newsproject.bitreport.pt → container :8080; otherwise WP redirects
# to http://localhost:8080/wp-login.php.
WORDPRESS_PUBLIC_URL: ${WORDPRESS_PUBLIC_URL:-http://localhost:8080}
# Disable WordPress cron (use system cron instead)
WORDPRESS_CONFIG_EXTRA: |
define('DISABLE_WP_CRON', true);
define('WP_DEBUG', false);
define('SCRIPT_DEBUG', false);
/* REST API — allow all origins for bridge access */
define('REST_API_ENABLED', true);
$_wp_public_url = getenv('WORDPRESS_PUBLIC_URL');
if ($_wp_public_url === false || $_wp_public_url === '') {
$_wp_public_url = 'http://localhost:8080';
}
$_wp_public_url = rtrim($_wp_public_url, '/');
/* If .env still defaults to the container URL but traffic comes via nginx (NPM → CT),
* infer WP_HOME from Host + X-Forwarded-Proto. Requires proxy headers (X-Forwarded-For),
* so raw :8080 access without WORDPRESS_PUBLIC_URL keeps local behaviour. */
$_container_local = in_array($_wp_public_url, array('http://localhost:8080', 'http://127.0.0.1:8080'), true);
if ($_container_local
&& !empty($_SERVER['HTTP_HOST'])
&& strpos($_SERVER['HTTP_HOST'], 'localhost') === false
&& strpos($_SERVER['HTTP_HOST'], '127.0.0.1') === false
&& !empty($_SERVER['HTTP_X_FORWARDED_FOR'])
) {
$_proto = 'http';
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$_first = strtolower(trim(strtok($_SERVER['HTTP_X_FORWARDED_PROTO'], ',')));
if ($_first === 'https') {
$_proto = 'https';
}
} elseif (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
$_proto = 'https';
}
$_wp_public_url = $_proto . '://' . $_SERVER['HTTP_HOST'];
}
define('WP_HOME', $_wp_public_url);
define('WP_SITEURL', $_wp_public_url);
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$_xf_proto = strtolower(trim(strtok($_SERVER['HTTP_X_FORWARDED_PROTO'], ',')));
if ($_xf_proto === 'https') {
$_SERVER['HTTPS'] = 'on';
}
}
volumes:
- wp_content:/var/www/html/wp-content
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini:ro
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/wp-json/wp/v2/", "-o", "/dev/null", "-w", "%{http_code}"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
volumes:
db_data:
wp_content: