IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> nginx 设置针对 CodeIgniter 的 rewrite 规则
猫猫草
post 2011-09-16 07:18:19, Fri
Post #1


猫猫猫
***

Group: Power Cat
Posts: 626
Joined: 2006-12-8
Member No.: 2



首先是 nginx.conf

代码
#user  nobody nobody;
worker_processes  2;

pid             /var/run/nginx.pid;

#max open files
worker_rlimit_nofile 1000;

events {
    worker_connections  1000;
}


http {
    error_log   /var/log/nginx/error.log crit;
    access_log  off;

    include             mime.types;
    default_type        application/octet-stream;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;

    keepalive_timeout   10;

    output_buffers      16 128k;

    client_body_timeout         3600;
    client_max_body_size        500m;

    server {
        include /nginx-listen.conf;

        charset utf-8;

        root   /www;
        index  index.php index.html index.htm;

#CodeIgniter rewrite begin
        location / {
            index index.php;

            if (-e $request_filename) {
                break;
            }

            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php?q=$1 last;
            }
        }
#CodeIgniter rewrite end

        # pass the PHP scripts to FastCGI server listening on local socket
        #
        location ~ \.php$ {
#CodeIgniter rewrite begin
            if (!-f $request_filename) {
                return 404;
            }
#CodeIgniter rewrite end
            fastcgi_pass   unix:/var/run/php5-fcgi.sock;
#            fastcgi_intercept_errors on;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }
    }
}


然后是 nginx 配置目录下的 fastcgi_params 包含文件,该文件必须正确拥有如下内容:

代码
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT   $document_root;


最后是 php.ini,可能(但不一定)需要打开

代码
cgi.fix_pathinfo=1
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 2024-10-17 07:28