Home > php教程 > php手册 > nginx与PHP的SERVER_NAME和HTTP_HOST详解

nginx与PHP的SERVER_NAME和HTTP_HOST详解

WBOY
Release: 2016-05-25 16:46:05
Original
1882 people have browsed it

ERVER_NAME对应Nginx配置文件中的server_name,通过fastcgi_param设置,如域名指向到IP而不在nginx中设置对应的server_name,PHP取SERVER_NAME为空,如果有多个server_name,取第一个.

例子代码如下:

server_name   www.phprm.com;
fastcgi_param  SERVER_NAME  $server_name;
Copy after login

HTTP_HOST包含在HTTP请求信息中,即请求的域名或IP,Nginx内为host.

HTTP_HOST 和 SERVER_NAME 的区别:

一:相同时满足以下三个条件:

1.服务器端口默认80

2.apache或nginx中ServerName设置正确

3.HTTP/1.1协议规范

二:不同点:

$_SERVER['HTTP_HOST']会根据客户端HTTP请求输出信息

$_SERVER['SERVER_NANE']会根据apache或nginx的配置文件中的ServerName值

当端口不为80时:

$_SERVER['HTTP_HOST']输出中会带有端口号

$_SERVER['SERVER_NAME']只会直接输出ServerName的值

所以,应尽量使用$_SERVER["HTTP_HOST"],保险,可靠.

永久链接:

转载随意!带上文章地址吧。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template