SERVER_NAME and HTTP_HOST of nginx and PHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.