Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lkmadushan's avatar

NGINX configuration for multi-tenant PHP application

map $http_accept $api_version {
    default 0;
    "application/vnd.dev.tenant.api.v1+json" 1;
}

server {

    listen 80;
    listen [::]:80;

    server_name ~^(?<tenant>.+)\.tenant\.dev$;
    root /var/www/v$api_version/public;
    index index.php;

    location / {

        if ($api_version = 0) {
            root /var/www/app/dist;
        }

        try_files $uri $uri/ /index.php$is_args$args;

        log_not_found off;

        error_page 404 =200 /index.html;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_param TENANT $tenant;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

How can I remove if condition from this configuration file? Is there any good way to accomplish this?

0 likes
0 replies

Please or to participate in this conversation.