Skip to content

Instantly share code, notes, and snippets.

@mubbi
Forked from lkmadushan/nginx.conf
Created August 19, 2018 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mubbi/aa8f37ae7c0ee49ab721aae310b11243 to your computer and use it in GitHub Desktop.
Save mubbi/aa8f37ae7c0ee49ab721aae310b11243 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