【原创】lnmp一键安装环境下,运行thinkphp5.1出现404错误

起初仿照默认文件server中的写法,引用的是enable-php.conf,但这个配置不支持tp5的pathinfo形式的url,因此改为引入enable-php-pathinfo.conf即可。

enable-php.conf内容:

location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}

enable-php-pathinfo内容:

location ~ [^/]\.php(/|$)
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}

pathinfo.conf内容:

fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name =404;

 

如果不是lnmp一键安装包安装的,可以按如下方式修改配置文件,亲测好用:

location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}

location ~ \.php/?.* {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
include fastcgi.conf;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注