在 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=$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作为 subomain 返回,而是返回*。那么对于 PHP 和 NGINX,我怎样才能获得真正的子域呢?