Codeigniter在nginx下的几个问题

本地的xampp测试没问题,上传到服务器就报503,查了一遍发现是session的问题,去php.ini中把session.auto_start打开就好了。

正常访问首页,点击进入后404,用index.php?访问倒是没问题,网上的一种解释是:

对于/index.php/abc这种url,Apache和lighttpd会按”index.php?abc”来解释,而nginx会认为是请求名字是“index.php”的目录下的abc文件的内容。所以CI在nginx下不配置rewrite是无法运行的,而在Apache和lighttpd则正常。

1
2
$config['index_page']  =  "index.php?";
$config['uri_protocol'] = "QUERY_STRING";

然后再去掉index.php

1
2
3
4
5
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
}

不过没测试这种方法是否有效,服务器FTP抽的实在连不上,不试了…

另外两种试过的方法也记录下

1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
listen 8081;
server_name localhost;

root /www/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_index index.php;
fastcgi_param SCRIPT_FILENAME /www/CodeIgniter/$fastcgi_script_name;

//fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}
}

2:

1
2
3
4
5
6
7
8
9
10
location /{
index index.html index.htm index.php;
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}