search
Homephp教程php手册nginx与PHP的SERVER_NAME和HTTP_HOST详解

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;

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"],保险,可靠.

永久链接:

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools