Skip to content

Instantly share code, notes, and snippets.

@lkmadushan
Last active May 1, 2021 01:29
Show Gist options
  • Save lkmadushan/56a4fbaa4ae41b97351ca63cbacff959 to your computer and use it in GitHub Desktop.
Save lkmadushan/56a4fbaa4ae41b97351ca63cbacff959 to your computer and use it in GitHub Desktop.
NGINX configuration for multi-tenant PHP application
map $http_accept $api_version {
default 0;
"application/vnd.example.v1+json" 1;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/marketing-app;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
listen [::]:80;
server_name ~^(?<tenant>.+)\.example\.com$;
root /var/www/v$api_version/public;
index index.php index.html index.htm;
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment