nginx-重写错误的url值


nginx - Rewriting wrong url values

嗨,我很难让我的网站使用nginx。我的网站基于Yii框架,并启用了干净的url格式。

问题的一个例子是搜索栏。搜索表单的操作url为/Site/index.php/real/search。搜索后,我被重定向到http://localhost/Site/index.php/index.php/real/view/id/4。现在问题来了。Nginx以某种方式在url中添加了一个额外的index.php。

因此,该页面不加载任何css或js,而是以纯html显示,其中包含大量错误。页面的实际url是http://localhost/Site/index.php/real/view/id/4

以下是名为default.conf 的nginx服务器配置

server { 
    listen 80; 
    server_name localhost:80; 
    root /site; 
    access_log /site/access_log.log;
    error_log /site/error_log.log;
    index index.php;
    client_max_body_size 1000M; 
    default_type text/html;
    charset utf-8;
    location = /favicon.ico {
        try_files /favicon.ico =204;
    }
    ## The main location is accessed using Basic Auth.
    location / {
        ## Use PATH_INFO for translating the requests to the
        ## FastCGI. This config follows Igor's suggestion here:
        ## http://forum.nginx.org/read.php?2,124378,124582.
        ## This is preferable to using:
        ## fastcgi_split_path_info ^(.+'.php)(.*)$
        ## It saves one regex in the location. Hence it's faster.
        location ~ ^(?<script>.+'.php)(?<path_info>.*)$ {
            include fastcgi_params;
            ## The fastcgi_params must be redefined from the ones
            ## given in fastcgi.conf. No longer standard names
            ## but arbitrary: named patterns in regex.
            fastcgi_param SCRIPT_FILENAME $document_root$script;
            fastcgi_param SCRIPT_NAME $script;
            fastcgi_param PATH_INFO $path_info;
            ## Passing the request upstream to the FastCGI
            ## listener.
            fastcgi_pass 127.0.0.1:9000;
        }
        ## Protect these locations. Replicating the .htaccess
        ## rules throughout the chive distro.
        location /protected {
            internal;
        }
        location /framework {
            internal;
        }
        ## Static file handling.
        location ~* .+'.(?:css|gif|htc|js|jpe?g|png|swf)$ {
            expires max;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=100 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }
    }
    ## We need to capture the case where the index.php is missing,
    ## hence we drop out of the path info thingie.
    location ~* /([^'.])$ {
        return 302 /index.php/$1;
    }
    ## Close up git repo access.
    location ^~ /.git {
        return 404;
    }
}

请让我知道我如何让nginx重写正确的url,我已经试着找到正确的配置好几个星期了,但没有成功。我将感谢任何帮助。

谢谢,Maxx

为什么不添加showScriptName=>false?这是我的配置

yii框架的Nginx配置

user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
    worker_connections 1024;
    # multi_accept on;
}
http {
    include       /etc/nginx/mime.types;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    tcp_nodelay  on;
    keepalive_timeout  65;
    gzip_disable        "MSIE [1-6]'.(?!.*SV1)";
    gzip_vary           on;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_comp_level     6;
    gzip_buffers        16 8k;
    gzip_http_version   1.1;
    gzip_types          text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    charset             utf-8;
    client_max_body_size 100m;
    fastcgi_read_timeout 300;
    server {
    listen       80;
    root   /var/www/mysite/frontend/web;
    server_name  mysite.loc;
    error_log /var/log/nginx/mysite-error.log;
    access_log /var/log/nginx/mysite-access.log;
    set $yii_bootstrap "index.php";
    location / {
        index  index.php index.html index.htm;
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }
    location ~ ^/(protected|framework|themes/'w+/views) {
        deny  all;
    }
    location ~ '.php$ {
    set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include fastcgi_params;
        fastcgi_intercept_errors        on;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }
    }
}

fastcgi_pass可以不同,例如localhost:9000、localhost:9001