php - Docker Nginx 连接到私有(private) docker 网络上的 PHP-FPM

标签 php docker nginx

我正在尝试将我的 docker nginx 容器连接到我的 docker php7 容器。我都连接到专用桥接网络,因为我希望我的 php 引擎离线。启动 nginx 容器时出现错误:

nginx: [emerg] host not found in upstream "php7" in 
 etc/nginx/conf.d/default.conf:11

我的 php 容器命令(首先运行):

docker run -d \
    --name php7 \
    -v /php7:/usr/local/etc \
    -v /www_data:/www \
    --network=priv-bridge-net \
    -p 9000:9000 \
    php:7.0.24-fpm

我的 nginx 命令:

docker run -d \
    --name nginx \
    -v /nginx_conf:/etc/nginx \
    -v /www_data:/usr/share/nginx/html \
    --network=priv-bridge-net \
    nginx:1.13.5

我的 nginx 配置:

server {
    index index.php index.html;
    server_name test;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php7:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

请帮我找出我做错了什么。谢谢! 第二个问题,我可以从 php 容器中删除 -p 9000:9000 吗,因为它与 nginx 服务器位于同一个桥接网络上。

最佳答案

好的,所以我上面的问题是正确的答案。我只是在启动容器的顺序方面遇到了麻烦(我也有反向代理和其他正在使用的代理,这有点令人困惑)。

对于任何想要将 docker nginx 连接到 docker php 的人来说,这是正确的设置:

我的 php 容器命令(首先运行):

docker run -d \
    --name php7 \
    -v /php7:/usr/local/etc \
    -v /www_data:/www \
    --network=priv-bridge-net \
    -p 9000:9000 \
    php:7.0.24-fpm

我的 nginx 命令:

docker run -d \
    --name nginx \
    -v /nginx_conf:/etc/nginx \
    -v /www_data:/usr/share/nginx/html \
    --network=priv-bridge-net \
    nginx:1.13.5

我的 nginx 配置:

server {
    index index.php index.html;
    server_name test;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /usr/share/nginx/html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php7:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

关于php - Docker Nginx 连接到私有(private) docker 网络上的 PHP-FPM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46515440/

相关文章:

ssl - Nginx错误: "No shared cipher".但是还有

python - Docker 容器 - 源文件消失

html - create-react-app 在服务器上部署时图标 png 文件加载失败

php - 无法创建 mySQL 表

php - Doctrine2 导致网站速度变慢

java - 如何使用在docker中运行的mysql来运行maven测试(使用maven-surefire-plugin)

macos - 即使没有容器正在运行,也无法删除图像

docker - 在 192.168.65.5 上查找 :53: no such host

php - 榆树和数据库事务

php - 从 URL 获取 HTML 字符串