使用PHP的子域Nginx和Catch
在Nginx中,我有一个如下设置:使用PHP的子域Nginx和Catch,php,nginx,Php,Nginx,在Nginx中,我有一个如下设置: server { listen 80; server_name *.example.com; location / { root /data/sites/www.example.com/widgets/public_html; index index.php index.html index.htm; try_files $uri $uri/ /index.php?q=$ur
server {
listen 80;
server_name *.example.com;
location / {
root /data/sites/www.example.com/widgets/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ .php$ {
root /data/sites/www.examples.com/widgets/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
如果我输入abc.example.com,它就会工作。现在在PHP中,我需要读取子域。我得到的子域如下所示:
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$urlSegments = parse_url($url);
$urlHostSegments = explode('.', $urlSegments['host']);
$subdomain = $urlHostSegments[0];
问题是,它返回的不是abc作为子主键,而是*。因此,对于PHP和NGINX,如何获得具有“一网打尽”功能的实际子域?试试:
array_shift(explode(".",$_SERVER['HTTP_HOST']));
要知道正确的变量
当然,这是HTTP\u主机,而不是服务器名
print_r($_SERVER);