PHP代码
网站配置根目录下 info.PHP
<?PHP
echo "<pre>";
echo $_SERVER['SERVER_NAME'];
host配置
127.0.0.1 www.my-search.com
127.0.0.1 www.my-play.com
Nginx配置
server {
listen 80;
server_name www.my-search.com www.my-play.com;
root "D:/PHPstudy_pro/WWW/PHPproject/mySearch/public";
index index.html index.PHP;
location / {
if (!-e $request_filename) {
rewrite ^/index.PHP(.*)$ /index.PHP?s=$1 last;
rewrite ^(.*)$ /index.PHP?s=$1 last;
break;
}
}
location ~ \.PHP(.*)$ {
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# fastcgi_split_path_info ^((?U).+\.PHP)(/?.+)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
}
PHP代码中获取 $_SERVER['SERVER_NAME'] 是域名1:http://www.my-search.com/info.php,还是域名2: http://www.my-play.com/info.phpserver name,结果都是Nginx配置中server_name的第一个值
配置的域名调换顺序,重启Nginx再访问
参考: https://www.cnblogs.com/linewman/p/9918112.html