How can nginx customize and set the $_SERVER variable of PHP?

11-03-2023

First, add the variable values you want to add to the nginx configuration. The file contents are as follows:

location ~ .php$ { try_files $uri =404; root /data/www.shuchengxian.com/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php ; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param ENVIRONMENT 'DEV'; # This is the variable you want to add, include fastcgi_params; }

Second, restart the nginx service.

Third, use PHP to output the $_SERVER array to see if there are any added values.

Array( [USER] => www [HOME] => /home/www [ENVIRONMENT] => DEV [REQUEST_TIME] => 1603264337......)

What are the characteristics of php? 1. Fast execution.

2. It has good openness and expansibility.

3. PHP supports a variety of mainstream and non-mainstream databases.

4. Object-oriented programming: PHP provides classes and objects.

5, the version update speed is fast.

6. It has rich functions.

7. Scalability.

8. Comprehensive functions, including graphic processing, encoding and decoding, compressed file processing, xml parsing, etc.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us