用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5574|回复: 3
收起左侧

求救nginx 配置怎么支持 PATH_INFO?

[复制链接]
发表于 2010-9-3 17:05:15 | 显示全部楼层 |阅读模式
求救nginx 配置怎么支持 PATH_INFO!
看了很多论坛的配置方法和官方的例子 始终不能成功!求救..!

nginx 0.7.65 + php5.3.2 (FastCGI)+ubuntu 10
XML复制代码
 
 
############/etc/nginx/nginx.conf
user www-data;
#worker_processes  1;
worker_processes 8;
 
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
 
#Specifies the value for maximum file descriptors that can be opened by this process. 2010 9.1
worker_rlimit_nofile 10000;
events {
    use epoll;
    #worker_connections 1024;
    worker_connections 10000;
    # multi_accept on;
}
 
http {
    #upstream myproject {
        #server 127.0.0.1:8000 weight=3;
        #server 127.0.0.1:8001;
        #server 127.0.0.1:8002;
        #server 127.0.0.1:8003;
    #}
    include       /etc/nginx/mime.types;
 
    access_log  /var/log/nginx/access.log;
    #charset utf-8;    
    sendfile        on;
    tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  60;
    tcp_nodelay        on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
   gzip_vary on;
 
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
 
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
 
########/etc/nginx/sites-enabled/default
server {
        listen   80;
 
        server_name 192.168.1.122;
 
        access_log  /var/log/nginx/localhost.access.log;
        location / {
                root   /var/www;
       
                index  index.html index.htm index.php;
 
                if (-f $request_filename) {
                        expires max;
                        break;
                }
 
                if (!-e $request_filename) {
                        rewrite ^/web/(.*)$ /web/index.php/$1 last;
                        #rewrite ^/(.*)$ /index.php/$1 last;
                }
        }
 
      location ~ \.php
     {
        root /var/www;
        fastcgi_index index.php;
        fastcgi_pass 192.168.1.122:900;
        set $path_info "";
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                set $real_script_name $1;
                set $path_info $2;
        }
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        include fastcgi_params;
     }
 
        location ~^/NginxStatus {
                stub_status on;
                access_log off;
        }
}
 
########/etc/nginx/fastcgi_params
fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
fastcgi_param  GATEWAY_INTERFACE   CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
#fastcgi_param SCRIPT_NAME $script;
#fastcgi_param PATH_INFO $path_info;
 
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
....
.....
 
复制代码


##ci
PHP复制代码
 
 
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'        Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'        Uses the REQUEST_URI
| 'ORIG_PATH_INFO'    Uses the ORIG_PATH_INFO
|
*/

$config['uri_protocol']    = "AUTO";
 
 
复制代码



主要是这句不知道改怎么写 或者 那配置有问题
XML复制代码
 
 
  location ~ \.php
     {
        root /var/www;
        fastcgi_index index.php;
        fastcgi_pass 192.168.1.122:900;
        set $path_info "";
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                set $real_script_name $1;
                set $path_info $2;
        }
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        include fastcgi_params;
     }
 
 
 
复制代码



比如http://192.168.1.122/web/ 和 http://192.168.1.122/web 这样是成功  
但是 http://192.168.1.122/web/index.php/task/这样就出现 404错误
 楼主| 发表于 2010-9-3 17:15:05 | 显示全部楼层
没人吗.  

http://192.168.1.122/web/ 和 http://192.168.1.122/web
http://192.168.1.122/web/index 和 http://192.168.1.122/web/index.php
这样是成功
其他的都错误
PHP复制代码
 
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'                        Default - auto detects
| 'PATH_INFO'           Uses the PATH_INFO
| 'QUERY_STRING'        Uses the QUERY_STRING
| 'REQUEST_URI'         Uses the REQUEST_URI
| 'ORIG_PATH_INFO'      Uses the ORIG_PATH_INFO
|
*/

$config['uri_protocol'] = "ORIG_PATH_INFO";
 
 
复制代码

这样出现全部页面都是主页
发表于 2010-9-3 23:51:10 | 显示全部楼层
对于Nginx,不建议在fastcgi下开启path_info,会产生文件上传安全漏洞,除此之外最好在程序中手动关闭:

@ini_set('cgi.fix_pathinfo', 0);
 楼主| 发表于 2010-9-4 17:38:32 | 显示全部楼层
谢谢问题解决了!
nginx配置
XML复制代码
 
 
 
 
 
server {
        listen   80;
        server_name 192.168.1.122;
        #charset utf-8;
        access_log  /var/log/nginx/localhost.access.log;
       location / {
                root   /var/www;
                index  index.html index.htm index.php;
 
                if (-f $request_filename) {
                        expires max;
                        break;
                }
 
                if (!-e $request_filename) {
                        rewrite ^/web/(.*)$ /web/index.php/$1 last;
 
                        #http://**/web/index?/admin/task
                        #http://**/web/index.php?/task
                        #http://**/web/index.php/task
                }
}
location ~ \.php
{
        root /var/www;
        fastcgi_index index.php;
        fastcgi_pass 192.168.1.122:900;
        set $path_info "";
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                set $real_script_name $1;
                set $path_info $2;
        }
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        include fastcgi_params;
}
 
###fastcgi_params文件
 
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  GATEWAY_INTERFACE   CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
#fastcgi_param SCRIPT_NAME $script;
#fastcgi_param PATH_INFO $path_info;
 
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
 
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
 
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
 
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
 
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
 
 
 
复制代码

本版积分规则