Mac nginx配置对php项目的支持

基础版本

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
    fastcgi_pass     127.0.0.1:9000;
    fastcgi_index    index.php;
    include          fastcgi_params;
    fastcgi_param    SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

这个时候,基本的php文件可以执行。

但是如果使用php项目,会有问题。因为有些路径不是以php结尾的。

升级版本

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php { 
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_split_path_info ^(.+.php)(/.+)$;  
    fastcgi_param   PATH_INFO  $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
    include         fastcgi_params;
}

fastcig_index ,如果请求的URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中。
为了防止,路径中多一个index.php,可以将这个值设置为none。

这样就支持tp等框架了。

原文地址:https://www.cnblogs.com/jiqing9006/p/14854541.html