codeigniter nginx rewrite规则配置【转】

转自:http://www.nginx.cn/1134.html

nginx如何配置才能支持codeigniter ?

1. codeigniter的url美化去掉index.php

 
1
2
3
4
5
        location / {
            root   html/gxtp;
            index  index.php;
            try_files $uri $uri/ /index.php?$uri&$args;
        }

2.与thinkphp一样codeigniter的url rewrite也是使用pathinfo来实现的,需要借助fastcgi_split_path_info来设置$_SERVER['PATHINFO']。

 
1
2
3
4
5
6
7
8
9
10
        location ~ ^.+.php {
           include        fastcgi_params;
           root           html/gxtp;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
           fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        }

codeigniter完整版nginx.conf规则

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    sendfile        on;
    keepalive_timeout  65;
 
    server {
        listen       80;
        server_name  www.264.cn;
 
        location / {
            root   html/kdw;
            index  index.php;
            try_files $uri $uri/ /index.php?$uri&$args;
        }
 
        location ~ ^.+.php {
           include        fastcgi_params;
           root           html/kdw;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_path_info;
           fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        }
    }
}
上一篇:一个App完成入门篇(七)- 完成发现页面


下一篇:HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置。