【问题标题】:Cookies don't work, apache to nginxcookie 不起作用,apache 到 nginx
【发布时间】:2015-07-08 08:23:32
【问题描述】:

我已将我的网站从 apache 移动到 nginx,但现在我的网站不想在我的用户尝试登录网站时向他们发送 cookie(或启动会话)。

这是我的登录脚本:

<?php
session_start();
include("includes/config.php");
$naam = mysql_real_escape_string($_POST["naam"]);
$wachtwoord = md5(mysql_real_escape_string($_POST["wachtwoord"]));

if (strlen($naam) > 0)
{
if (strlen($wachtwoord) > 0)
{
    $uQuery = mysql_query("SELECT * FROM users WHERE username = '".$naam."' AND password = '".$wachtwoord."' LIMIT 1");
    if (mysql_num_rows($uQuery))
    {
        while($lid = mysql_fetch_array($uQuery)) {
            $id = $lid["id"];
        }
        $_SESSION["lid"] = $id;
        header("Location: me.php");
    } else {
        header("Location: index.php?error=1");
        }
    }
}
?>

这是我用来连接 MySQL 的(我的配置文件):

<?php

$host = "ip address";
$username = "root";
$password = "password";
$db = "test";

 $con = mysql_connect($host, $username, $password);
if (!$con){ die('Verbinding mislukt: ' . mysql_error()); }
$db = mysql_select_db($db, $con);
if (!$db){ die ('Kan database niet vinden: ' . mysql_error()); } 
?>

有人知道怎么解决吗?

这是我的 nginx 配置:

#
# The default server
#
server {
listen       80 default_server;
server_name  ;

#charset koi8-r;

#access_log  logs/host.access.log  main;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
    root   /usr/share/nginx/html/shine;
    index index.php   index.html index.htm;
}

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

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;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {

    root           /usr/share/nginx/html/shine;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}

谢谢!

【问题讨论】:

  • PHP 以前如您所说的那样工作,所以没关系。您应该向我们提供配置文件
  • 之前一切正常,我使用的是相同的 PHP 版本。我已经测试了我的网站和 MySQL 服务器之间的连接,并且运行良好..
  • 我已经编辑了帖子。 :)
  • 当我尝试登录时,登录页面接受我的用户名和密码,并将我重定向到您登录时将重定向到的页面。成功登录后的页面重定向我回到我没有登录的错误的索引。
  • 我从您问题的第一阶段就知道这一点。你的 PHP 代码没问题。你在你的 ngnix 配置中遗漏了一些东西。看,here,这些就是我们需要的东西。你的 ngninx 配置。

标签: php apache session cookies nginx


【解决方案1】:

感谢所有帮助。 我已经找到了解决方法。 cookie 保存文件夹不存在并且没有正确的 cmod..

这个命令解决了它:

mkdir /var/lib/php/session chmod -R 777 /var/lib/php/session

【讨论】:

    猜你喜欢
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 2015-01-01
    相关资源
    最近更新 更多