How to set the $ _ SERVER variable in Nginx

Source: Internet
Author: User
Tags configuration settings

In some PHP, the ENVIRONMENT constant can be defined to distinguish the development ENVIRONMENT from the production ENVIRONMENT, for example:

Define ('enable', isset ($ _ SERVER ['ci _ env'])? $ _ SERVER ['ci _ env']: 'development ');
Switch (ENVIRONMENT)
{
Case 'development ':
Error_reporting (-1 );
Ini_set ('display _ errors ', 1 );
Break;
 
Case 'testing ':
Case 'production ':
Ini_set ('display _ errors ', 0 );
If (version_compare (PHP_VERSION, '5. 3', '> = '))
  {
Error_reporting (E_ALL &~ E_NOTICE &~ E_DEPRECATED &~ E_STRICT &~ E_USER_NOTICE &~ E_USER_DEPRECATED );
  }
Else
  {
Error_reporting (E_ALL &~ E_NOTICE &~ E_STRICT &~ E_USER_NOTICE );
  }
Break;
 
Default:
Header ('http/1.1 503 Service Unavailable. ', TRUE, 503 );
Echo 'The application environment is not set correctly .';
Exit (1); // EXIT_ERROR
}

Here, $ _ SERVER ['ci _ env'] is defined in where?

Nginx configuration settings $ _ SERVER variables

Open an nginx website configuration:

Location ~ \. Php $ {
Try_files $ uri = 404;
Root/usr/share/nginx/html/tanteng. me/public;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param MYENV 'dev ';
Include fastcgi_params;
}

Fastcgi_param MYENV 'dev' is the newly added statement.

Print $ _ SERVER in PHP:


......
"SERVER_ADDR" => "192.168.10.31"
"SERVER_NAME" => "www. tanteng. me"
"SERVER_PORT" => "80"
"SERVER_SOFTWARE" => "nginx/1.9.11"
"SERVER_PROTOCOL" => "HTTP/1.1"
"SERVER_ADMIN" => ""
"SERVER_SIGNATURE" => ""
"SCRIPT_NAME" => "/index. php"
"REDIRECT_STATUS" => "200"
"REQUEST_URI" => "/test/redis"
& Quot; REMOTE_PORT & quot; = & gt; 61290
"DOCUMENT_URI" => "/index. php"
"REQUEST_METHOD" => "GET"
"REMOTE_ADDR" => "192.168.10.1"
"CONTENT_TYPE" => ""
"DOCUMENT_ROOT" => "/usr/share/nginx/html/tanteng. me/public"
"MYENV" => "DEV"
"CONTENT_LENGTH" => ""
"QUERY_STRING" => ""
"SCRIPT_FILENAME" => "/usr/share/nginx/html/tanteng. me/public/index. php"
"SCRIPT_URL" => "/index. php"
"SCRIPT_URI" => http://www.111cn.net
"PHP_SELF" => "/index. php"
......

In this way, we can see an extra variable named "MYENV.

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.