+ -
当前位置:首页 → 问答吧 → 真是有点儿无语

真是有点儿无语

时间:2011-05-10

来源:互联网

废话少说,还是“无法加载模块Index”的问题

环境:Ubuntu Server 11.04

nginx(0.8.54)配置:
server {
    listen 80;
    server_name test.xxx.com;
    access_log /var/log/nginx/test.access.log;
    error_log /var/log/nginx/test.error.log;
   
    root /home/xxx/www/test;
    index index.html index.php;
   
    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?s=$1 last;
            break;
        }
    }
   
    location ~ .*\.(php|php5)?$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}

Conf/config.php:
<?php
return array(
    'APP_DEBUG' => true,
    'DB_TYPE'=> 'mysql',
    'DB_HOST'=> 'localhost',
    'DB_NAME'=> 'test',
    'DB_USER'=> 'root',
    'DB_PWD'=> '123456',
    'DB_PORT'=> '3306',
    'DB_PREFIX'=> 'test_',
    'APP_GROUP_LIST' => 'Home,Admin',
    'DEFAULT_GROUP' => 'Home',
    'URL_MODEL' => 1,
    'URL_ROUTER_ON' => true,
    'URL_CASE_INSENSITIVE' => false,
);
?>

已经在/Lib/Action/Home/Index下创建IndexAction.class.php文件,并将/etc/php5/cgi/php.ini中的cgi.fix_pathinfo=0修改为cgi.fix_pathinfo=1

可是为什么打开http://localhost还是显示“无法加载模块Index”,而且打开http://localhost/index.php/Home/Index/index直接就是404 Not Found?

而如果在/Lib/Action下创建一个空的IndexAction.class.php文件(没有index方法),却可以直接访问到/Tpl/default/Home/Index/下的index.html文件,但是访问其他URL仍然是404 Not Found。

不知道是我配置的问题,还是ThinkPHP的问题?求解释

作者: uuwtf   发布时间: 2011-05-10

把你的地址 http://localhost/index.php/Home/Index/index 换成 http://localhost/Home/Index/index 试一试, 这样的话 应该和http://localhost是一样效果, 显示无法加载Index模块, 因为你IndexAction.class.php 是空的, 写一点简单的代码吧。
  1. <?php
  2. class IndexAction extends Action{
  3. function index(){
  4. echo "index";
  5. }
  6. }
  7. ?>
复制代码
这是你 nginx配置的问题。  nginx是不支持pathinfo的。

   
    location ~ .*\.(php|php5)?$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
改为
   
    location ~ .*\.(php|php5) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
试一试。 这样能开启pathinfo, 但是很不安全。 你到网上搜索一下"nginx 畸形解析" 就知道了。

估计你也不明白
  if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?s=$1 last;
            break;
        }
这段 指令的意思, 你有这段指令不用配置pathinfo的。

作者: luofei614   发布时间: 2011-05-10