【问题标题】:Atomic deployment: after an Nginx reload, PHP-FPM is still pointing to the old webroot原子部署:Nginx 重新加载后,PHP-FPM 仍然指向旧的 webroot
【发布时间】:2014-09-23 19:14:39
【问题描述】:

我正在尝试使用 Nginx 和 PHP5.5-FPM 使用 Opcache 进行原子部署。

这个想法只是改变nginx.conf中的webroot然后运行

nginx 重载

我期望的是 Nginx 将等待当前请求结束,然后重新加载自身,将新的 webroot 路径传递给 PHP FPM,但它不起作用:PHP FPM 仍在从旧目录加载 PHP 文件。 我在 Ngnix 中使用(未记录的)$realpath_root 是为了不获取符号链接(/prod/current),而是获取真实路径。 该技术记录在这里:http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ 调试 Nginx 我可以清楚地看到它正在传递新的(真实的)路径。

    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/current/web"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 posix_memalign: 00000000010517A0:4096 @16
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "SCRIPT_FILENAME"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/prod/releases/20140923124417/web"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/index.php"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 fastcgi param: "SCRIPT_FILENAME: /www/htdocs/prod/releases/20140923124417/web/app.php"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "DOCUMENT_ROOT"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/prod/releases/20140923124417/web"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 fastcgi param: "DOCUMENT_ROOT: /www/htdocs/prod/releases/20140923124417/web"
    2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "APPLICATION_ENV"

为了让它工作,我必须运行一个

php-fpm 重新加载

但我失去了一些请求。

'recv() 在从上游读取响应头时失败(104: Connection reset by peer)'

这是我正在使用的 nginx 文件:

server {
  listen              26023;

  server_name         prod.example.com;

  client_max_body_size  20m;
  client_header_timeout 1200;
  client_body_timeout   1200;
  send_timeout          1200;
  keepalive_timeout     1200;


  access_log  /var/logs/prod/nginx/prod.access.log main;
  error_log   /var/logs/prod/nginx/prod.error.log;

  set $root_location /var/www/htdocs/prod/current/web;
  root $root_location;

  try_files   $uri $uri/ /index.php?$args;
  index       index.php;


  location ~ \.php$ {
    fastcgi_pass    unix:/var/run/php5-fpm/prod.sock;
    fastcgi_index   index.php;

    include         fastcgi_params;

    fastcgi_connect_timeout 1200;
    fastcgi_send_timeout    1200;
    fastcgi_read_timeout    1200;
    fastcgi_ignore_client_abort on;

    fastcgi_param   SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param   DOCUMENT_ROOT   $realpath_root;

    fastcgi_param   APPLICATION_ENV live;
    fastcgi_param   HTTPS           $thttps;
  }

}

这是池配置:

:~$ curl http://127.0.0.1/fpm_status_prod
pool:                 prod
process manager:      dynamic
start time:           23/Sep/2014:22:42:34 +0400
start since:          1672
accepted conn:        446
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       49
active processes:     1
total processes:      50
max active processes: 2
max children reached: 0
slow requests:        0

有什么建议吗?

【问题讨论】:

    标签: deployment nginx php


    【解决方案1】:

    我解决了这个问题,我也在使用 APC 作为类加载器,但它没有被清除。

    【讨论】:

    • 为什么要使用 APC OpCache?它添加了哪些功能,是否缩短了可测量的时间?我很感兴趣,因为缓存中有陈旧的东西一直是我的主要问题,收益很少。
    • APCu 结合 OpCache 是 composer 推荐的:getcomposer.org/doc/articles/autoloader-optimization.md
    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 2021-05-24
    • 2022-01-14
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    相关资源
    最近更新 更多