Nginx and PHP server_name and http_host detailed

Source: Internet
Author: User

Erver_name corresponds to the server_name in the Nginx configuration file by Fastcgi_param settings, such as the domain name pointing to IP instead of setting the corresponding nginx in server_name,php for null server_name. If there are multiple server_name, take the first one.

Example

The code is as follows Copy Code

server_name www.111cn.net;
Fastcgi_param server_name $server _name;

Http_host is included in the HTTP request information, that is, the requested domain name or the Ip,nginx within the host.

The difference between http_host and server_name:

One: The following three conditions are met:

1. Server Port Default 80

ServerName set correctly in 2.apache or Nginx
3.http/1.1 Protocol Specification

Two: Different points:

$_server[' http_host ' will output information based on client HTTP requests
$_server[' Server_nane ' will be based on the servername value in the Apache or nginx configuration file

When the port is not 80 o'clock
The $_server[' http_host ' output will have a port number
$_server[' server_name ' will only output servername values directly

Therefore, should try to use $_server["Http_host"], insurance, 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.