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
解决办法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。