default.template
server {
listen 80 default_server;
add_header Content-Security-Policy "frame-ancestors 'self' https://${content_security_policy_url}";
add_header X-XSS-Protection "1; mode=block";
root /var/www/prod/public_html;
include /etc/nginx/fcgiwrap.conf;
include /etc/nginx/mime.types;
index index.php index.sec index.html;
error_page 405 =200 $uri;
# Create route of /dashboard to the domain name dashboard
location /dashboard {
proxy_pass http://$host/dashboard;
}
location / {
try_files $uri $uri/ /index.php?$args;
# set_real_ip_from ::/0;
# set_real_ip_from 0.0.0.0/0;
# real_ip_header X-Forwarded-For;
fastcgi_param HTTPS $fastcgi_param_https_variable;
error_page 500 502 503 504 /500.html;
}
location ~ .php|.sec$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTPS $fastcgi_param_https_variable;
# fastcgi_param sitePath "https://$host/";
include fastcgi_params;
}
location = /500.html {
root /usr/share/nginx/html;
internal;
}
}
I get subdomain value which is dynamic and I want to set the SERVER_NAME with the value that sets in HTTP_HOST
Ex: in URL if I hit abc.test.com in browser,$_SERVER[‘SERVER_NAME’] should return the same value or xyz.abc.com, $_SERVER[‘SERVER_NAME’] should be xyz.abc.com.
I tried the following
1.
server {
server_name ~^(?<subdomain>.+).abc.com$;
}
with this solution, If I print $_SERVER['SERVER_NAME'] in code, it doesnt replace the regex with actual value
2. location ~ .php|.sec$ {
fastcgi_param SERVER_NAME $http_host
}
This will not set the expected data, SERVER_NAME will be empty
/etc/nginx/fcgiwrap.conf file has
fastcgi_param SERVER_NAME $server_name;
PHP and NGINX are running under docker container
It will be great If I get any inputs on how to set S_SERVER[‘SERVER_NAME’] with HTTP_HOST value
TIA
Rajeshwari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.