thinkphp - nginx下TP3.2访问页面总是404

查看:389
本文介绍了thinkphp - nginx下TP3.2访问页面总是404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

配置如下 这样访问时就会报404localhost/road/index.php/home/user/index 在nginx下这种情况应该修改配置文件的哪个地方呢?百度了好多 我看每个人的答案都不一样 试了几个都不成功 哪位大神帮我看看我这个配置基础上应该改哪几个地方呢 我在php.ini文件中把cgi.fix_pathinfo=1 TP的URL_MODEL设置为3

    listen      80;
    server_name localhost;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html index.php;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME
       $document_root$fastcgi_script_name;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
       include fastcgi_params;
    }
}

解决方案

这是我测试onethink用的配置 可以参考一下

server {
    listen 80;
    server_name onethink.dev www.onethink.dev;
    
    root /vagrant/www/onethink;
    index index.php;
    
    location / {
        if ( -f $request_filename) {
            break;    
        }

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

    location ~ \.php {
        set $script $uri;
        set $path_info "";
        if ($uri ~ "^(.+\.php)(/.+)") {
            set $script $1;
            set $path_info $2;    
        }    

        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$script;
        fastcgi_param SCRIPT_NAME $script;
        try_files $uri =404;
    }
}

这篇关于thinkphp - nginx下TP3.2访问页面总是404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆