php-fpm 和 nginx 会话问题

2024-02-15

过去一周左右我一直遇到这个问题。我一直在开发一个严重依赖会话的 PHP 项目。由于某种原因,过去几天我们在保存会话方面遇到了麻烦。知道为什么吗?

这是错误:

Warning: Unknown: open(/tmp/sess_mmd0ru5pl2h2h9bummcu1uu620, O_RDWR) failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
Warning: session_start(): open(/tmp/sess_mmd0ru5pl2h2h9bummcu1uu620, O_RDWR) failed: Permission denied (13)

nginx 版本:

nginx version: nginx/1.0.11

PHP-FPM 配置:

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix.

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
include=/etc/php-fpm.d/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Default Value: none
pid = /var/run/php-fpm/php-fpm.pid

; Error log file
; Default Value: /var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

; See /etc/php-fpm.d/*.conf

nginx.conf:

#######################################################################
#
# This is the main Nginx configuration file.
#
# More information about the configuration options is available on
#   * the English wiki - http://wiki.nginx.org/Main
#   * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################

#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
#   http://wiki.nginx.org/NginxHttpMainModule
#
#----------------------------------------------------------------------

user              nginx nginx;
worker_processes  5;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


#----------------------------------------------------------------------
# Events Module
#
#   http://wiki.nginx.org/NginxHttpEventsModule
#
#----------------------------------------------------------------------

events {
    worker_connections  4096;
}


#----------------------------------------------------------------------
# HTTP Core Module
#
#   http://wiki.nginx.org/NginxHttpCoreModule
#
#----------------------------------------------------------------------

http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

        index index.php index.html index.htm;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
        server {
                listen 80;
                server_name stats.smilingdevil.com;

                error_page   404   /404.php;

                root /var/www;

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

                location / {
                        set $page_to_view "/index.php";
                        try_files $uri $uri/ @rewrites;
                        root /var/www/;
                        index index.php;
                }

                location @rewrites {
                        if ($uri ~* ^/([a-z0-9]+)$) {
                                set $page_to_view "/$1.php";
                                rewrite ^/([a-z]+)$ /$1.php last;
                        }
                }

                location ~ \.php$ {
                        include /etc/nginx/fastcgi.conf;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
                }
        }
}

只需将 /var/lib/php/session/ 的所有权从 apache 更改为 nginx,而不是进行全局读取。

sudo chown -R nginx:nginx /var/lib/php/session/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

php-fpm 和 nginx 会话问题 的相关文章

  • php 数组中出现意外的 json 输出结构

    我正在尝试转换动态数据 如何从 PHP 获取此 JSON JSON 122240cb 253c 4046 adcd ae81266709a6 item 0 3 这就是我所做的 但它不起作用 PHP json array 122240cb 2
  • 一种无需 JavaScript 即可在 PHP 中确定浏览器宽度的方法?

    首先有吗 或者我必须使用javascript 我希望能够更改使用的 CSS 因此 frex 我可以为移动设备或其他设备加载较小的字体 不幸的是 仅使用 PHP 无法检测用户分辨率 如果您使用 Javascript 则可以在 cookie 中
  • PHP 通过 SSL 连接到 MS SQL

    我想要实现的目标非常简单 我想通过安全连接从 PHP 脚本连接到外部 MS SQL 数据库 然而 这已被证明是有问题的 到目前为止 经过三个小时的研究 我不知所措 客户端的平台是Ubuntu 这意味着我无法使用SQLSRV 安全连接已经在不
  • PHP MongoDb 驱动程序:如何设置执行代码的超时

    我有以下代码 它在 MongoDb 端执行一段代码 mongoCode new MongoCode Some JS code db gt execute mongoCode array socketTimeoutMS gt 1000000
  • AWS-PHP-SDK / SNS 直接寻址返回错误

    您好 我正在使用 Laravel 4 设置来利用 AWS SNS 向我的 iOS 设备发送推送消息 从 AWS 控制台向我的设备发布命令效果很好 然后我尝试从 PHP sns AWS get sns sns gt publish array
  • 是否可以将路由参数传递给 Laravel 中的控制器构造函数?

    是否可以将路由参数 或路由段 注入到控制器构造函数中 您找到一些代码来澄清我的问题 class TestController protected param public function construct paramFromRoute
  • PHP:读取所有传入 HTTP 请求的类 [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 如何在 JavaScript 中创建服务器端进度指示器?

    我想在我的网站中创建一个部分 用户可以在其中进行一些简单的操作update纽扣 这些中的每一个update按钮将发送到服务器 并在幕后进行长时间的处理 当服务器处理数据时 我希望用户有某种进度指示器 例如进度条或文本百分比 我使用 jQue
  • 使用 PHP glob 列出 FTP 服务器上的文件不起作用

    我使用此代码来访问目录 location files pictures glob location png 我想使用 FTP 访问远程路径 location opendir ftp user password host name files
  • 使用值填充的 Symfony2 自定义字段类型

    这是先前问题的后续问题Symfony2 自定义表单类型或扩展 https stackoverflow com questions 24079288 symfony2 custom form type or extension 我正在尝试为订
  • 在 foreach 中使用 QueryPath 的多个查找

    我正在使用 QueryPath 和 PHP 这发现 eventdate 没问题 但不会为 dtstart 返回任何内容 qp htmlqp url foreach qp gt find table schedule gt find tr a
  • 使用 XPATH(和 PHP)从样式属性中选择背景 url

    我只想从此背景图像样式属性中选择 url 这可以通过 XPATH 实现吗 a href http www test com style background image none test a 我有类似的东西 url xpath gt qu
  • 如何在 Windows 上安装 Zend 框架

    安装 Zend Framework 就是这么简单 是的 对 好吧 我正在写一本初学者的书 有一件不太详细的事情是最重要的部分 安装该死的东西 浏览了几个小时的快速入门指南后 它只说 下载 Zend 添加包含目录 bla bla 然后就完成了
  • 在同一个 nginx 服务器块上公开多个 api uri

    Goal 我的目标是在同一个 nginx 服务器上设置多个后端 api 容器 http localhost 80 api account gt 调用 http account service 9000 http localhost 80 a
  • 使用 PHP 从 Mongo 解码 JSON

    我已经看过这个线程 PHP 解码嵌套 JSON https stackoverflow com questions 3555335 php decode nested json并没有设法用它来解决我的问题 我目前正在从 Mongo 获取 J
  • Jquery一键提交多个同名表单

    我有动态创建的循环表单 我需要一键提交所有表单 我正在遵循下面的代码 你能建议我怎么做吗 谢谢
  • PHP session_regenerate_id 和黑莓浏览器

    问候 我正在开发一个登录系统 并陷入了黑莓浏览器身份验证的困境 他们似乎对 PHP 的 session regenerate id 有问题 有人可以建议替代方案吗 以下是身份验证和登录脚本 UPDATE看来会话一般都不起作用 拿出 sess
  • PHP 表单 - 带验证蜜罐

    我有以下内容 效果很好 但对垃圾邮件机器人开放 我想放入蜜罐 而不是验证码 下面的代码适用于验证姓名 电子邮件 消息 但我无法让它与蜜罐一起工作 任何人都可以查看 蜜罐 代码并告诉我如何修复它吗 我希望表单给出 success2 不允许垃圾
  • 矩形超出边界是什么意思

    PPB Graphics2D PaintImageData 矩形超出界限是什么意思 我几乎在我检查的每一段代码中都看到了它 最新的代码是 define my consumer key define my consumer secret oa
  • 通过 htaccess 将 PNG 解析为 PHP 仅适用于本地服务器,但不适用于网络服务器

    我用 PHP 创建了一个动态 PNG 图片 为了使用 PNG 扩展名 我创建了一个包含以下内容的 htaccess 文件 AddType application x httpd php png 在我的本地 XAMPP 服务器上 一切工作正常

随机推荐