thinkphp5.1无法访问hello方法(在nginx中的配置)

环境介绍:LNMP

问题介绍:

从github上下载完最新版的thinkphp5.1之后,正常是可以运行的,比如下图



但是,当我们访问里面自带的hello方法(http://shop.xiaobudiu.top/index/index/hello),会发现无法跳转,显示的仍然是上面的这个页面。



这种问题基本都出在nginx rewrite跳转上,事实上这里的确是这样。将nginx对应的server的子配置文件相应的rewrite规则添加上就好了,效果:



配置文件代码:/etc/nginx/conf.d/shop.xiaobudiu.top

server {
    listen       80;
    server_name  shop.xiaobudiu.top;

    charset utf-8;
    error_log    /etc/nginx/logs/error/shop.xiaobudiu.top.log error;
    access_log  /etc/nginx/logs/access/shop.xiaobudiu.top.log main;

    root   /data/shop/public;
    index  index.html index.htm index.php;

    location /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location /static/original {
    }

    location /static {
        access_log off;
    }


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


   error_page  404 403 500 502 503 504  /404.html;

    location = /404.html {
        root   /data/errorPage;
    }


   location ~ \.php$ {
        fastcgi_pass   unix:/dev/shm/php-cgi.sock;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
   }

    location ~ /\.ht {
        deny  all;
    }


}

主要就是这段代码,一定要添加上。

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


注:部分小伙伴提到了修改php.ini配置文件中的cgi.fix_pathinfo,这里建议大家非必要情况不要开启这个参数,存在安全问题,我这里没有开启,一样是可以访问的,不是吗。



注:thinkphp5.1 chm手册 https://download.csdn.net/download/m_nanle_xiaobudiu/10526467

猜你喜欢

转载自blog.csdn.net/m_nanle_xiaobudiu/article/details/80948538