PHP中SERVER_NAME获取的问题

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

解决办法

  1. 两个域名分开配置

  2. Nginx相关配置是可以解决的,我比较的懒。懒的找

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...