ERVER_NAME corresponds to server_name in the Nginx configuration file and is set through fastcgi_param. for example, if the domain name directs to an IP address and the server_name parameter is not set in nginx, the SERVER_NAME parameter for PHP is null. if there are multiple server_name, first
ERVER_NAME corresponds to server_name in the Nginx configuration file and is set through fastcgi_param. for example, if the domain name directs to an IP address and the server_name parameter is not set in nginx, the SERVER_NAME parameter for PHP is null. if there are multiple server_name, take the first one.
The sample code is as follows:
Server_name www.phpfensi.com;
Fastcgi_param SERVER_NAME $ server_name;
HTTP_HOST is included in the HTTP request information, that is, the requested domain name or IP address. Nginx is the host.
Differences between HTTP_HOST and SERVER_NAME:
1. meet the following conditions simultaneously:
1. the default server port is 80.
2. set ServerName correctly in apache or nginx
3. HTTP/1.1 Protocol specification
II. differences:
$ _ SERVER ['http _ host'] outputs information based on the client's HTTP request
$ _ SERVER ['server _ NANE '] is based on the ServerName value in the apache or nginx configuration file.
When the port is not 80:
$ _ SERVER ['http _ host'] will contain the port number in the output.
$ _ SERVER ['server _ name'] only the ServerName value is output directly.
Therefore, use $ _ SERVER ["HTTP_HOST"] as much as possible, which is safe and reliable.