Why $_SERVER['SCRIPT_NAME'] return 'index.php' when I use nginx rewrite? -


I am using the YII framework and everything is fine on Apache server, but this is incorrect on NGNX. When I request the URL www.test.com/index.php/a/b, $ _SERVER ['SCRIPT_NAME'] return '/index.php' what exactly I want, but when I URL www.test I request com / A / B, which is rewritten in the same file as 'index.php', $ _SERVER ['SCRIPT_NAME'] 'index.php' which is different from Apache. My NG Con is as follows:

  server {set $ host_path "/ data / yii / application"; Access_log off; Server_name www.yii.com; Root $ host_path; Set $ ​​Yii_bootstrap "index.php"; Charset UTF-8; Place / index.html $ yii_bootstrap; Try_files $ uri $ uri / $ yii_bootstrap? $ Args; } Place ~ ^ / (protected | framework | theme / \ w + / view) {reject all; } # Awake processing of calls to unexpected files by Yii space ~ \. (Js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar) $ {try_files $ uri = 404; } # 127.0.0.1:9000 # location ~ \ .php {fastcgi_split_path_info ^ (. + \ .php) (. *) $; Pass PHP scripts on the FastCGI server ### yii Call to unwanted PHP files Set $ ​​fsn / $ yii_bootstrap; If (-f $ document_root $ fastcgi_script_name) {Set $ ​​fsn $ fastcgi_script_name; } Fastcgi_pass 127.0.0.1:9001; Includes fastcgi_params; Fastcgi_param SCRIPT_FILENAME $ document_root $ fsn; #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI fastcgi_param PATH_INFO $ fastcgi_path_info; Fastcgi_param PATH_TRANSLATED $ document_root $ fsn; } Place ~ /\.ht {reject all; }}    

This part is false:

  Set $ ​​Yii_bootstrap "index.php"; Place / index.html $ yii_bootstrap; Try_files $ uri $ uri / $ yii_bootstrap? $ Args; }   

It should be:

  location / {index index.html index.php; Try_files $ uri $ uri / /index.php$uri?$args; }   

Also see:

-

and this part:

  location ~ \ .php {Fastcgi_split_path_info ^ (. + \ .php) (. *) $; ### yii Call to unwanted PHP files Set $ ​​fsn / $ yii_bootstrap; If (-f $ document_root $ fastcgi_script_name) {Set $ ​​fsn $ fastcgi_script_name; } Fastcgi_pass 127.0.0.1:9001; Includes fastcgi_params; Fastcgi_param SCRIPT_FILENAME $ document_root $ fsn; #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI fastcgi_param PATH_INFO $ fastcgi_path_info; Fastcgi_param PATH_TRANSLATED $ document_root $ fsn; }   

should be replaced with:

  place ~ ^ (? & Lt; script & gt ;. + \ .php) (? & Lt ; Pathinfo & gt;;) $ {Try_files $ script = 404; Fastcgi_pass 127.0.0.1:9001; Includes fastcgi_params; Fastcgi_param SCRIPT_FILENAME $ document_root $ script; #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 has specified them for the CGI Fastcase_Param PathFIFFFFF $ path; Fastcgi_param PATH_TRANSLATED $ document_root $ script; }   

-

And you should avoid things like this:

 set $ host_path "/ data / yii / Application "; Root $ host_path;   

should be:

  root / data / or / application;   



Comments