多个Nginx + PHP容器

时间:2018-05-17 16:30:19

标签: php docker nginx docker-compose traefik

我有这个配置: - 1个Nginx(dev)docker + 1个Php(dev)docker - 1个Nginx(prod)docker + 1 Php(pro)docker

我使用traefik和docker-compose。 问题是我无法将dev php docker连接到dev nginx docker ......我找不到" File。"错误。这意味着nginx无法找到fastcgi配置。

这是我的docker-compose:

server {
   listen       80;
   server_name  trombi.xxx.xyz www.trombi.xxx.xyz;

   #charset koi8-r;
   #access_log  /var/log/nginx/log/host.access.log  main;


    location / {
       root   /usr/share/nginx/trombi.xxx.xyz;
       index  index.html index.htm index.php;
       try_files $uri $uri/ /index.php$is_args$args;
     }

   #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   /usr/share/nginx/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$ {
        fastcgi_index   index.php;
        fastcgi_pass    php:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    /usr/share/nginx/trombi.xxx.xyz/$fastcgi_script_name;
    }
}

这是我对该网站的php conf:

2018/05/17 06:59:47 [error] 8#8: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.19.0.5, server: trombi.xxx.xyz, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://172.20.0.4:9000", host: "trombi.xxx.xyz"
    172.19.0.5 - 
- [17/May/2018:06:59:47 +0000] "GET /info.php HTTP/1.1" 404 47 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 OPR/52.0.2871.97"

日志中出现此错误:

fastcgi_pass    php:9000;

感谢您的帮助:)我无法找到它的来源......

UDPATE:感谢@Constantin Galbenu Juste需要改变nginx conf:

fastcgi_pass    php-dev:9000;

到:

Product->Scheme->FirebaseCore.

1 个答案:

答案 0 :(得分:1)

在docker-compose中,可以通过名称访问服务。 Docker将自动解析服务的IP地址(您不需要使用IP地址)。

在您的情况下,PHP服务的名称为php-dev,而不只是php

解决方案是将fastcgi_pass php:9000;替换为fastcgi_pass php-dev:9000;