thinkphp5 在lnmp一键安装包上没有加index.php访问出现404错误
那是因为pathinfo没有被支持,要在配置上加上支持pathinfo和去掉index.php
找到: /usr/local/nginx/config/vhost/项目名.config
然后在配置文件添加如下代码:
#这一句支持pathinfo
include enable-php-pathinfo.conf;
#下面这几行隐藏index.php
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
配置文件修改后如下:
server
{
listen 80;
#listen [::]:80;
server_name thinkphp5.cn ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/thinkphp5.cn/public;
include other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
include enable-php-pathinfo.conf; #这一句支持pathinfo
#下面这6行隐藏index.php
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
access_log /home/wwwlogs/thinkphp5.cn.log;
}
当ThinkPHP5在LNMP一键安装包上遇到没有index.php的404错误时,原因是缺少对pathinfo的支持。解决方法是编辑项目配置文件,添加对pathinfo的支持和隐藏index.php的设置。具体操作包括在配置文件中包含enable-php-pathinfo.conf,并使用rewrite规则重写URL以隐藏index.php。
770

被折叠的 条评论
为什么被折叠?



