无法登录,似乎是服务器端cookie相关的问题


Cannot log in, cookie related issue on the server side it seems

这是一个全新的Drupal 7的快速安装。

使用firebug,我可以看到在我尝试登录后,cookie在响应头中被发送回来。页面被重定向到主页(/节点)。会话记录也保存在会话表中。没有错误。服务器错误日志中也没有错误。

同一服务器托管其他具有登录功能的站点。同一浏览器可以正常登录其他网站。比如Wordpress。Cookie已启用

服务器正在运行Nginx, PHP-fpm

附件是nginx设置为我的网站。我不确定它是否与干净的url有关。从浏览器中,我看到了干净的url。我可以进入/用户,/用户/注册,/用户/密码页面。

server
{
  listen       80;
  server_name  www.testd720.com;
  index        index.php index.html index.htm;
  root         /opt/www/drushtest/web1;
  #error_page 404 = @drupal;
  #location / {
  #          # This is cool because no php is touched for static content
  #          try_files $uri $uri/ @rewrite;
  #          expires max;
  #}
  #location @drupal {
  #   rewrite ^(.*)$ /index.php?q=$1 last;
  #}
  location / {
      if (!-e $request_filename) {
          rewrite  ^/(.*)$   /index.php?q=$1  last;
          break;
      }
  }
  location ~ .*'.(php|php5)?$
  {
    #fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi.conf;
  }
  access_log logs/testd720.log main;
}
头:

Cache-Control   no-cache, must-revalidate, post-check=0, pre-check=0
Connection  keep-alive
Content-Language    en
Content-Type    text/html; charset=utf-8
Date    Thu, 07 Mar 2013 09:47:37 GMT
Etag    "1362649657"
Expires Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified   Thu, 07 Mar 2013 09:47:37 +0000
Location    http://www.testd720.com/node
Server  nginx/1.2.0
Set-Cookie  SESS26bc541d314e909277ae077251e81e7a=qu7a2apzFE9ALHnLWc04N-t_JoHhh2UCR2MkmKROVG0; expires=Sat, 30-Mar-2013 13:20:57 GMT; path=/tmp; domain=.testd720.com; HttpOnly
Transfer-Encoding   chunked
X-Powered-By    PHP/5.4.3

问题出在cookie路径设置上:

Set-Cookie  SESS26bc541d314e909277ae077251e81e7a=qu7a2apzFE9ALHnLWc04N-t_JoHhh2UCR2MkmKROVG0;
   expires=Sat, 30-Mar-2013 13:20:57 GMT;
   path=/tmp;
   domain=.example.com;
   HttpOnly

在这里,你指定你的浏览器,这个cookie应该只使用在url在以/tmp开头的网站。

你相当肯定的错误的cookie路径参数(这是路径用于限制pths在您的网站在此cookie适用)与cookie存储路径在您的服务器上-这实际上不存在,cookie不存储在服务器上-(在php这是由会话管理。Save_path设置如果你的会话是通过web服务器上的文件管理的,这是默认配置,会话存储在服务器上,它们的名称是cookie名称)。