fix(wordpress): public URL for wp-admin behind reverse proxy

Set WP_HOME/WP_SITEURL from WORDPRESS_PUBLIC_URL so login does not redirect
to http://localhost:8080 when using https://newsproject.bitreport.pt.
Trust X-Forwarded-Proto for HTTPS behind NPM. Document in .env.example and
docs/deployment.md checklist.

Refs: BIT-345
Made-with: Cursor
This commit is contained in:
Artur Moreira committed 2026-03-24 03:41:35 +00:00
1 parent 7095765669
commit ab0ea3c785
3 files changed
+21

No files matched your search

+2
View File
@@ -103,6 +103,7 @@ A stack real está versionada em **`wordpress/docker-compose.yml`** (não duplic
|------|----------------|
| Database | **MariaDB 11** (`mariadb:11`), serviço `db`, porta 3306 só na rede Compose |
| WordPress | `wordpress:6-php8.3-apache`, `WORDPRESS_DB_HOST: db:3306` |
| URL pública | `WORDPRESS_PUBLIC_URL` no `.env` do host (ex.: `https://newsproject.bitreport.pt`) — define `WP_HOME` / `WP_SITEURL` e evita redirect para `http://localhost:8080` no login |
| Arranque | `depends_on: db` com `condition: service_healthy` |
| Volumes | `db_data` (MySQL), `wp_content` (uploads/plugins) |
| Healthchecks | `db`: script oficial `--innodb_initialized`; `wordpress`: `curl` ao REST `/wp-json/wp/v2/` |
@@ -137,6 +138,7 @@ pm2 startup
- [ ] Bridge dependencies installed and built
- [ ] Frontend dependencies installed and built
- [ ] WordPress Docker stack running (`docker compose up -d`)
- [ ] `WORDPRESS_PUBLIC_URL=https://newsproject.bitreport.pt` em `wordpress/.env` (alinhado com NPM / browser)
- [ ] WordPress configured (admin user, permalink structure `/%category%/%postname%/`)
- [ ] Bridge invalidator plugin activated in WP
- [ ] PM2 processes started and saved
+5
View File
@@ -11,3 +11,8 @@ MYSQL_PASSWORD=change_this_wordpress_password
WP_ADMIN_USER=admin
WP_ADMIN_EMAIL=[email protected]
# WP_ADMIN_PASSWORD — set in vault; do not store here
# Public URL WordPress uses for redirects (wp-login, wp-admin). On the LXC behind NPM use HTTPS + host:
# WORDPRESS_PUBLIC_URL=https://newsproject.bitreport.pt
# Local Docker-only dev (browser → localhost:8080): omit or use http://localhost:8080
WORDPRESS_PUBLIC_URL=http://localhost:8080
+14
View File
@@ -30,6 +30,10 @@ services:
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);
@@ -37,6 +41,16 @@ services:
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, '/');
define('WP_HOME', $_wp_public_url);
define('WP_SITEURL', $_wp_public_url);
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') {
$_SERVER['HTTPS'] = 'on';
}
volumes:
- wp_content:/var/www/html/wp-content
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini:ro