原子部署:在Nginx重新加载之后,PHP-FPM仍然指向旧的webroot

时间:2014-09-23 19:14:40

标签: deployment nginx php

我试图用Nginx和PHP5.5-FPM与Opcache进行原子部署。

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

  

nginx reload

我期待的是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 reload

但我失去了一些请求。

  从上游读取响应头时,

' recv()失败(104:对等连接重置)'

这是我使用的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;
  }

}

这是池conf:

:~$ 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

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

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