Centos7+nginx上部署laravel(同时解决laravel访问新建路由出现404的问题、No input file specified的问题、URL模式问题)

版权声明:== https://github.com/fyonecon == https://blog.csdn.net/weixin_41827162/article/details/84398806

laravel访问新建路由出现404问题、No input file specified问题这两个问题可能是因为用了一键lnmp,不知道实际nginx配置造成的,百度问题也很难解决,部署过程中也碰到了不少莫名其妙等问题。

-

#1. 一般直接在nginx.conf里面添加如下即可完成URL的路由访问

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

但是,我用的是一键lnmp https://blog.csdn.net/weixin_41827162/article/details/82914526,里面的nginx添加了如上代码,新建路由访问时依然404。

最终在nginx.conf里面找到一句include enable-php.conf,里面有一句 try_files $uri =404; 是这句每次访问新路由时都是404。

[root@localhost conf]# vi enable-php.conf

注释掉try_files $uri =404;就行了就可以了。
[root@localhost conf]# service nginx restart

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

-

#2. 404问题总结:

扫描二维码关注公众号,回复: 4208759 查看本文章

1)找到try_files $uri =404; 然后将它注释掉。地方可能在nginx.conf、enable-php.conf等文件。

2)添加下面代码:

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

 3)重启nginx即可:service nginx restart

-

#3. 接下来解决No input file specified  问题:

这个问题等出现是因为 主机未开启 pathinfo 函数导致的。需要启用 cgi.fix_pathinfo 参数

参考:https://blog.csdn.net/a787031584/article/details/53400250

1)进入php.ini文件。将cgi.fix_pathinfo的值改成1

[root@localhost ~]# find / -name php.ini
/usr/local/php/etc/php.ini
[root@localhost ~]# vi /usr/local/php/etc/php.ini

2)然后到配置域名解析的文件下(一般是以域名命名的配置文件)。加上这三句:

比如我加在nginx.conf下:

astcgi_split_path_info ^(.+\.php)(/.+)$;  
fastcgi_param   PATH_INFO   $fastcgi_path_info;  
fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name; 

-

4. 最终laravel部署完毕,新建路由访问成功:

ThinkPHP5也成功(感叹一下,TP真的比laravel好部署万倍,各种省心):

-

-------拓展--------------

pathinfo URL写法:

  • laravel:/index.php/参数
  • TP5:/?s=/参数   或者  /index.php?s=/参数

TP5等URL模式比较方便,可以适用于pathinfo和兼容模式;laravel以上配置的是pathinfo模式,而且官方推荐等也是pathinfo

模式。

-

猜你喜欢

转载自blog.csdn.net/weixin_41827162/article/details/84398806
今日推荐