简体   繁体   English

Docker上的NginX和Php-Fpm

[英]NginX and Php-Fpm on docker

I have an official docker NginX container (NginX:latest) connected to official Php-Fpm (php:7.2-fpm) based container using bind mount for config and source code (for testing purpose). 我有一个官方的docker NginX容器(NginX:latest)连接到了官方的基于Php-Fpm(php:7.2-fpm)的容器,并使用绑定挂载进行配置和源代码(用于测试)。 They are communicating through FastCGI. 他们正在通过FastCGI进行通信。 I'm running Docker Edge for Windows 2.0.0. 我正在运行Windows 2.0.0的Docker Edge。 (engine 18.09). (引擎18.09)。

The php app is serving html pages and there are some XHR requests on every page to get JSON data from the same app. php应用程序正在提供html页面,并且每个页面上都有一些XHR请求,以从同一应用程序获取JSON数据。

Everything work well except the second XHR request generates an error. 一切正常,除了第二个XHR请求生成错误。 The page itself loads, then within the document ready event two XHR requests are being processed, but only one of them (most often the first) finishes with success and the second one causing 404 error. 页面本身会加载,然后在文档就绪事件中处理两个XHR请求,但是只有其中一个(最常见的是第一个)成功完成,第二个导致404错误。

Response contains No input file specified. 响应中未No input file specified. error and docker console shows these errors: 错误,泊坞窗控制台显示以下错误:

Php-fpm: WARNING: [pool www] child 8 said into stderr: "ERROR: Unable to open primary script: /var/www/html/web/app.php (No such file or directory)" php-fpm: WARNING: [pool www] child 8 said into stderr: "ERROR: Unable to open primary script: /var/www/html/web/app.php (No such file or directory)"

Nginx: *235 FastCGI sent in stderr: "Unable to open primary script: /var/www/html/web/app.php (No such file or directory)" while reading response header from upstream, client: 192.168.16.2, server: my-server.com, request: "GET /cli/cli_har_rc.php?EVENT=GET&THREAD=2 HTTP/1.0", upstream: "fastcgi://192.168.16.3:9000", host: "my-server.com", referrer: "https://my-server.com/cli/cli_har.php" Nginx: *235 FastCGI sent in stderr: "Unable to open primary script: /var/www/html/web/app.php (No such file or directory)" while reading response header from upstream, client: 192.168.16.2, server: my-server.com, request: "GET /cli/cli_har_rc.php?EVENT=GET&THREAD=2 HTTP/1.0", upstream: "fastcgi://192.168.16.3:9000", host: "my-server.com", referrer: "https://my-server.com/cli/cli_har.php"

Which is odd because the file exists and when I use the same request in separate browser tab it works well. 这很奇怪,因为文件存在,并且当我在单独的浏览器选项卡中使用相同的请求时,它运行良好。 It also sometimes happens that requests' order is interchanged by browser and only the first one has success no matter which one it is. 有时还会发生这样的情况,即请求的顺序被浏览器互换,并且无论第一个是成功的,都只有第一个成功。 It seems like the requests concurrency plays the role. 似乎请求并发起着作用。

NginX site.conf: NginX site.conf:

server {
    set $request_url $request_uri;

    listen 80;
    server_name my-server.com;
    root /var/www/html/web;

    location / {
        try_files $uri /app.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass fpm_cw:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/app.php;
        fastcgi_param SCRIPT_NAME /app.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param REQUEST_URI $request_url;
    }
}

When I put some time distance to XHR request call (1-2s) it works as expected. 当我与XHR请求调用之间有一段距离(1-2秒)时,它可以按预期工作。 It seems to be problem with some processing delays within docker on windows processing. Windows处理上的docker内部处理延迟似乎是问题。 I am yet to check it on Linux machine. 我还没有在Linux机器上检查它。

You can also tell PHP-FPM to use only one process by setting the pm directive to static and pm.maxchildren to 1 in the pool configuration file, and thus prevent any concurrent access to the files. 您还可以通过在池配置文件中将pm指令设置为static并将pm.maxchildren设置为1来告诉PHP-FPM仅使用一个进程,从而防止对文件的任何并发访问。

https://github.com/docker/for-win/issues/2005#issuecomment-391822753 https://github.com/docker/for-win/issues/2005#issuecomment-391822753

The problem was caused by combination of Docker bind mounts on windows. 该问题是由Windows上的Docker绑定安装的组合引起的。 I didn't go further, but it seems the problem is solved on production machine with production container where are no bind mounts but whole project copied in build time. 我没有走得更远,但是似乎问题在带有生产容器的生产机器上解决了,该生产机器没有绑定安装,但是整个项目在构建时被复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM