歡迎您光臨本站 註冊首頁

nginx+php無法讀取session的值

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

nginx+php無法讀取session的值

nginx+php無法讀取session的值


在php.ini設置了默認的session.save_path的路徑為/tmp,保存的時候,可以保存成sess_*文件的,但讀取的時候,就是讀取不出來內容,將文件夾及文件設置設置為777也不行.手動指定了文件夾也是同樣的問題lnmp安裝教程:http://blog.haohtml.com/index.php/archives/6051
phpinfo:http://72.46.130.155/phpinfo.php
nginx.conf的配置/usr/local/nginx/conf/nginx.conf

user  www www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   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           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
include /usr/local/nginx/conf/vhost/*.conf;
測試的sess.php內容,在本地apache沒有問題
<?php
session_start();
//session_save_path('./img');

//echo session_save_path() . "<br>";
$act = $_GET['act'];

if ($act == 'show') {
         echo session_save_path()."<br>";
   print_r($_SESSION);
} else {
   $_SESSION['test'] = 'abc';
         echo 'Welcome to page #1';

         $_SESSION['favcolor'] = 'greendd';
         $_SESSION['animal']   = 'caddt';
         $_SESSION['time']     = time();

         // Works if session cookie was accepted
         echo '<br /><a href="?act=show">page 2</a>';

         echo session_save_path()."<br>";

print_r($_SESSION);
   
}
?>
《解決方案》

已經解決了.是session.cookie_path引起的,我把他改成/tmp了,應該用/就可以了
《解決方案》

{:2_166:}好貼,把解決問題得詳細過程貼出來,方便後來者呀
《解決方案》

php.ini session path配置的問題~

[火星人 ] nginx+php無法讀取session的值已經有762次圍觀

http://coctec.com/docs/service/show-post-2102.html