|
437 | 437 | if [ -n "$PROXY_URL" ]; then |
438 | 438 | echo "Configuring nginx proxy..." |
439 | 439 |
|
440 | | - # Create nginx directory if it doesn't exist |
441 | | - mkdir -p .ddev/nginx |
442 | | - |
443 | | - # Extract hostname from PROXY_URL for Host header |
444 | | - PROXY_HOST=$(echo "$PROXY_URL" | sed 's|https\://||' | sed 's|http://||' | sed 's|/.*||') |
445 | | - |
446 | | - # Process nginx configuration template - use the current add-on source if available |
447 | | - NGINX_MAIN_TEMPLATE="" |
448 | | - NGINX_SNIPPET_TEMPLATE="" |
449 | | - |
450 | | - # Try to find the templates in the add-on metadata |
451 | | - if [ -f ".ddev/addon-metadata/ddev-kanopi-wp/config/nginx/nginx-site-main.conf" ]; then |
452 | | - NGINX_MAIN_TEMPLATE=".ddev/addon-metadata/ddev-kanopi-wp/config/nginx/nginx-site-main.conf" |
453 | | - fi |
454 | | - |
455 | | - if [ -f ".ddev/addon-metadata/ddev-kanopi-wp/config/nginx/nginx-site.conf" ]; then |
456 | | - NGINX_SNIPPET_TEMPLATE=".ddev/addon-metadata/ddev-kanopi-wp/config/nginx/nginx-site.conf" |
457 | | - fi |
| 440 | + # Get the actual docroot from DDEV configuration |
| 441 | + DOCROOT=$(grep '^docroot:' .ddev/config.yaml | cut -d: -f2 | tr -d ' ' || echo "web") |
458 | 442 |
|
459 | | - if [ -n "$NGINX_MAIN_TEMPLATE" ]; then |
460 | | - # Get the actual docroot from DDEV configuration |
461 | | - DOCROOT=$(grep '^docroot:' .ddev/config.yaml | cut -d: -f2 | tr -d ' ' || echo "web") |
462 | | - |
463 | | - # Create complete nginx configuration to override DDEV's default |
464 | | - # First remove #ddev-generated marker, then do all replacements |
465 | | - sed '1s/^#ddev-generated$//' "$NGINX_MAIN_TEMPLATE" | \ |
466 | | - sed "s|PROXY_URL_PLACEHOLDER|$PROXY_URL|g; s|HOST_PLACEHOLDER|$PROXY_HOST|g; s|/var/www/html/public|/var/www/html/$DOCROOT|g" \ |
467 | | - > ".ddev/nginx_full/nginx-site.conf" |
468 | | - echo " ✅ Complete nginx proxy configuration created (docroot: $DOCROOT)" |
469 | | - elif [ -n "$NGINX_SNIPPET_TEMPLATE" ]; then |
470 | | - # Fallback to snippet approach |
471 | | - sed "s|PROXY_URL_PLACEHOLDER|$PROXY_URL|g; s|HOST_PLACEHOLDER|$PROXY_HOST|g" \ |
472 | | - "$NGINX_SNIPPET_TEMPLATE" > ".ddev/nginx/nginx-site.conf" |
473 | | - echo " ✅ Nginx proxy snippet created" |
| 443 | + # Check if nginx_full/nginx-site.conf exists |
| 444 | + if [ -f ".ddev/nginx_full/nginx-site.conf" ]; then |
| 445 | + # Extract hosting domain and environment from PROXY_URL |
| 446 | + # Example: https://dev-sitename.pantheonsite.io -> domain=pantheonsite.io, env=dev |
| 447 | + PROXY_HOST=$(echo "$PROXY_URL" | sed 's|https\://||' | sed 's|http://||' | sed 's|/.*||') |
| 448 | + |
| 449 | + # Determine hosting domain based on provider |
| 450 | + case "$HOST_PROVIDER" in |
| 451 | + "pantheon") |
| 452 | + HOSTING_DOMAIN="pantheonsite.io" |
| 453 | + ;; |
| 454 | + "wpengine") |
| 455 | + HOSTING_DOMAIN="wpengine.com" |
| 456 | + ;; |
| 457 | + "kinsta") |
| 458 | + HOSTING_DOMAIN="kinsta.cloud" |
| 459 | + ;; |
| 460 | + *) |
| 461 | + HOSTING_DOMAIN="" |
| 462 | + ;; |
| 463 | + esac |
| 464 | + |
| 465 | + # Update the nginx configuration with actual values |
| 466 | + sed -i.bak \ |
| 467 | + -e "s|HOSTING_ENV-HOSTING_SITE.HOSTING_DOMAIN|$PROXY_HOST|g" \ |
| 468 | + -e "s|/var/www/html/web|/var/www/html/$DOCROOT|g" \ |
| 469 | + ".ddev/nginx_full/nginx-site.conf" |
| 470 | + rm -f ".ddev/nginx_full/nginx-site.conf.bak" |
| 471 | + |
| 472 | + echo " ✅ Nginx proxy configuration updated (docroot: $DOCROOT, proxy: $PROXY_HOST)" |
474 | 473 | else |
475 | | - echo " ⚠️ Nginx template not found - proxy configuration not updated" |
| 474 | + echo " ⚠️ .ddev/nginx_full/nginx-site.conf not found - proxy configuration not updated" |
476 | 475 | fi |
477 | 476 | fi |
478 | 477 |
|
|
0 commit comments