neuqliu 发表于 2015-4-1 23:40:49

配置NGINX去除index.php失败

我在部署到nginx之后带着index.php可以访问,但是去除index.php一直失败,求大神指点。这是我的配置:
location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            root /usr/share/nginx/html;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_index index.php;
            include fastcgi_params;
      }

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


访问一直提示:File not found.

相知犹按剑 发表于 2015-4-1 23:42:35

nginx版本是多少,安装nginx时候是否选择了相应模块?

neuqliu 发表于 2015-4-1 23:56:24

nginx是1.6.2,你说的选择相应的模块指的是什么?

z86823237 发表于 2015-4-2 00:49:40

兄弟,File not found. 应该是你的 FastCGI模块返回的php文件未找到。
错误:fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
这句话要改成:
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;

详细内容请看:http://www.chenyudong.com/archives/codeigniter-in-nginx-and-url-rewrite.html

neuqliu 发表于 2015-4-2 22:08:27

本帖最后由 neuqliu 于 2015-4-2 22:09 编辑

z86823237 发表于 2015-4-2 00:49
兄弟,File not found. 应该是你的 FastCGI模块返回的php文件未找到。
错误:fastcgi_param SCRIPT_FILENAM ...
我试过那篇文章的做法,结果一样也是File not found,不知道还可能哪有问题呢,刚学PHP{:soso_e109:}

whlives 发表于 2015-4-3 09:42:22

location /   {         index index.php;         if (!-e $request_filename) {                rewrite ^/(.*)$ /index.php?$1 last;                break;         }   }
试试这个我也是找了好久才可以的

具体可以看http://www.cnblogs.com/whlives/p/4360617.html

TurboY 发表于 2015-4-14 12:45:13

其实这个在nginx网站上已经提出了一个更好的解决方法 try_files,不用再rewrite了。
参考代码如下:
server {
......
index index.php;
location / {
    try_files $uri $uri/ /index.php;
    ......
}
......

zakokun 发表于 2015-4-20 17:29:38

我的配置是这样的,运行正常


server {
    listen   8081;
    server_name localhost;

    root/Users/zhanghongwen/code/CodeIgniter;

    index index.php;
    try_files $uri $uri/ @rewrite;
    location @rewrite {
      rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
      include fastcgi_params;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_indexindex.php;
      fastcgi_paramSCRIPT_FILENAME/Users/zhanghongwen/code/CodeIgniter/$fastcgi_script_name;

    }
}

kissgxd 发表于 2016-6-21 15:09:42

使用楼上的方法成功了,看样子是rewrite 和 try files不知道有什么差别
页: [1]
查看完整版本: 配置NGINX去除index.php失败