diff --git a/docs/deployment.md b/docs/deployment.md index 0a65300..c96bbaf 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -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 diff --git a/wordpress/.env.example b/wordpress/.env.example index 8678188..a7508c4 100644 --- a/wordpress/.env.example +++ b/wordpress/.env.example @@ -11,3 +11,8 @@ MYSQL_PASSWORD=change_this_wordpress_password WP_ADMIN_USER=admin WP_ADMIN_EMAIL=admin@bitreport.pt # 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 diff --git a/wordpress/docker-compose.yml b/wordpress/docker-compose.yml index 3232e13..67b0565 100644 --- a/wordpress/docker-compose.yml +++ b/wordpress/docker-compose.yml @@ -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