前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >laravel+nginx配置好后报错500的一些问题记录,已解决

laravel+nginx配置好后报错500的一些问题记录,已解决

作者头像
sinnoo
发布2020-11-13 15:57:11
1.4K0
发布2020-11-13 15:57:11
举报
文章被收录于专栏:技术人生

一、检查ngxin配置,以下是我的nginx配置

这里粘贴下源码供大家参考:

代码语言:javascript
复制
user  www www; 
worker_processes  4; 
events { 
    worker_connections  1024; 
} 
 
http { 
    include       mime.types; 
    default_type  application/octet-stream; 
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' 
                      '$status $body_bytes_sent "$http_referer" ' 
                      '"$http_user_agent" "$http_x_forwarded_for"'; 
     
    sendfile        on; 
    keepalive_timeout  65; 
 
    upstream web { 
        server   unix:/run/php-fpm/www.sock weight=100 max_fails=10 fail_timeout=30; 
    } 
    server { 
        listen       80; 
        server_name  31.297.228.158;     
        root /var/www/buxingjie/public/; 
        index index.php index.html index.htm; 
 
        access_log  /var/log/nginx/access.log  main; 
        error_log   /var/log/nginx/error.log  debug; 
         
        location ~ \.php$ {    
            fastcgi_pass   web; 
            fastcgi_split_path_info  ^(.+\.php)(.*)$; 
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name; 
            fastcgi_param  PATH_INFO $fastcgi_path_info; 
            include fastcgi_params;         
            include fastcgi.conf;       
        } 
  
        location / {           
            try_files $uri $uri/ /index.php?$query_string; 
        }                      
        #if (!-d $request_filename)     
        #{ 
        #    rewrite ^/(.+)/$ /$1 permanent; 
        #} 
        # 去除index action 
        #if ($request_uri ~* index/?$)  
        #{ 
        #    rewrite ^/(.*)/index/?$ /$1 permanent; 
        #} 
        # 根据laravel规则进行url重写    
        #if (!-e $request_filename)     
        #{ 
        #    rewrite ^/(.*)$ /index.php?/$1 last; 
        #    break; 
        #} 
        #error_page   500 502 503 504  /50x.html; 
        #location = /50x.html { 
        #    root   html; 
        #} 
    } 
}

二、我们看下fastcgi.conf和fastcgi_params文件,fastcgi.conf文件底部增加一行

代码语言:javascript
复制
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/:/var/www/buxingjie/";

三、对项目根目录下两个文件夹赋权storage和bootstrap/cache

chmod -R 777 storage

四、检查laravel需要的PHP拓展是否都已经安装

检查是否已经安装:

php -m | grep 'json'

也可以在项目根目录下index.php文件中输出phpinfo()进行查看

假如nginx配置没问题,index.php文件中写入exit('cs');应该会在浏览器上显示出cs;

五、告诫一下大家的话

ngxin+laravel已经配置好,浏览器访问报错500,搞了一下午一直没有解决,搜索各种方式,没有任何提示,PHP报错也开了,nginx报错也查了

后来放弃了,开始研究源码,跟着index.php里面内容一步步看源码($request = Illuminate\Http\Request::capture()从这里开始,主要是这里没继续执行),打印断点测试,然后发现是json拓展没有安装,php.ini里面没有配置

安装拓展(如何安装PHP拓展参考这个链接),配置php.ini,就解决了问题,所以有时候没思路时,可以跟着代码一步步走一走,或许会更好。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档