I would like to set the variable $sub
conditionally dependent on $request_uri
and $host
.
map $request_uri $sub {
default front;
~^/api/.* api;
~^/rest/.* rest;
}
map $host $sub {
hostnames;
#default $sub; # Tried, no success
ping.* ping;
admin.* admin;
}
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_X_SUB $sub;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location / {
try_files $uri $uri/ /index.php;;
}
}
I thought nginx will not overwrite $sub
in map $host $sub
if the hostname is not in the list, but unfortunatly it just blanks out $sub
.
So basically it should be like if $host
is "ping" or "admin" set $sub
accordingly. If hostname did not match, check for $request_uri
.
Any idea how to archive that statement?
EDIT: Extended the config.
0 Answers