0

我正在尝试Cakephp在我的 Nginx 服务器上设置我的项目。

现在一切正常,但是有一个问题。

当我尝试传递参数时,例如mydomain.com/cake/users/view?searchvalue=test

它不起作用。因为没有发送查询值(即它们被删除、为空或消失)。

现在我不知道是我的Cakehtaccess 干扰还是我的服务器

(因此我为什么要在上面Stackoverflow而不是在上面发布ServerFault,请注意,如果您认为这应该是服务器故障,我会删除它并转到那里)。

这是我的 Nginx 文件:

    server {
    listen       80;
    server_name  my-domain.com;
    return 301 http://www.my-domain.com$request_uri;
}

server{
    listen      80 default;
    server_name     www.my-domain.com;


        location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }

                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include        /etc/nginx/fastcgi_params;
        #include fastcgi_params;
        }


    location ~ ^/cake/(.+)$ {
        index  index.php;

    set $val $1;

        try_files $uri $uri/ /cake/app/webroot/$val /cake/app/webroot/index.php/$val;

    }

如果您需要更多信息,请告诉我!

这是一些附加信息,这是它在尝试访问 my-domain.com/admin/test/servertest 时打印的内容?laura 这是我回显服务器变量时的内容:

   array (
  'USER' => 'apache',
  'HOME' => '/var/www',
  'FCGI_ROLE' => 'RESPONDER',
  'QUERY_STRING' => ' ', <---- **this is the problem**
  'REQUEST_METHOD' => 'GET',
  'CONTENT_TYPE' => '',
  'CONTENT_LENGTH' => '',
  'SCRIPT_FILENAME' => '/usr/share/nginx/html/cake/app/webroot/index.php',
  'SCRIPT_NAME' => '/cake/app/webroot/index.php',
  'PATH_INFO' => '',
  'REQUEST_URI' => '/cake/admin/employees/servertest?laura',
  'DOCUMENT_URI' => '/cake/app/webroot/index.php',
  'DOCUMENT_ROOT' => '/usr/share/nginx/html',
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'GATEWAY_INTERFACE' => 'CGI/1.1',
  'SERVER_SOFTWARE' => 'nginx/1.0.15',
  'REMOTE_ADDR' => '**.**.***.***',
  'REMOTE_PORT' => '53811',
  'SERVER_ADDR' => '***.**.***.***',
  'SERVER_PORT' => '80',
  'SERVER_NAME' => 'www.my-domain.com',
  'REDIRECT_STATUS' => '200',
  'HTTP_HOST' => 'www.my-domain.com',
  'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0',
  'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
  'HTTP_COOKIE' => 'bloglic_data[credentials]=Q2FrZQ%3D%3D.XG7at918B4h8lCRNBCdwg0Avi3ZNLdAn28Dl3vfOxaQkJAoJFYxZ0s1a%2Fp3RLB2%2B5krPCIBKFboN4y1X4lY4%2FFautJJ7ce6VyN%2BOgLFbR4KUzn5g7QGDlZS2YqB%2FbZ%2FghYfKzcZvzkYYkvtj9dQkozRMaUPWY8%2F910tf7fnpk8EFAQ%3D%3D; CAKEPHP=7c411r3pc7vhjk3vjqjoplmtk3',
  'HTTP_CONNECTION' => 'keep-alive',
  'PHP_SELF' => '/cake/app/webroot/index.php',
  'REQUEST_TIME_FLOAT' => 1382965704.0475,
  'REQUEST_TIME' => 1382965704,
)
4

2 回答 2

1

尝试在您的try_files

/cake/app/webroot/index.php/$val;

对此

/cake/app/webroot/index.php/$val$is_args$query_string;
于 2013-10-28T22:45:45.553 回答
1

强制性if is evilhttp ://wiki.nginx.org/IfIsEvil

归功于 pasela:https ://gist.github.com/pasela/3052624

#
# nginx configuration example for CakePHP 2.x
#
server {
  listen       80;
  server_name  cakephp2.example;
  root         /var/www/cakephp2/app/webroot;

  access_log  /var/log/nginx/cakephp2.access.log;
  error_log  /var/log/nginx/cakephp2.error.log;

  location / {
      index  index.php;
      try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
      include        fastcgi_params;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      fastcgi_pass   127.0.0.1:9000;
  }

  location ~ \.php/ {
      include        fastcgi_params;
      fastcgi_split_path_info ^(.+\.php)(/.*)$;
      fastcgi_param  PATH_INFO $fastcgi_path_info;
      fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      fastcgi_pass   127.0.0.1:9000;
  }

  location = /favicon.ico {
      log_not_found off;
      access_log off;
  }

  location = /robots.txt {
      log_not_found off;
      access_log off;
  }

  #error_page  404              /404.html;
  #location = /404.html {
  #    root   /usr/share/nginx/html;
  #}  

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   /usr/share/nginx/html;
  }

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  location ~ /(\.ht|\.user.ini|\.git|\.hg|\.bzr|\.svn) {
      deny  all;
  }

}

这是我第一次安装 Cake 时遇到 mod_rewrite 问题后遇到的问题。你可以改变周围的东西,例如我使用unix socketwithfastcgi_pass而不是TCP/IP socket.

于 2013-10-30T15:56:51.340 回答