docker nginx和php-fpm podman之间的通信

dxxyhpgq  于 2023-05-16  发布在  Docker
关注(0)|答案(2)|浏览(151)

我想用php-fpm设置一个nginx来运行symfony。
为此,我创建了一个pod调用webservicepodman pod create --name webservice -p 8080:80
然后启动一个php-fpm:

podman run -ti \
--name php7 \
--pod webservice \
--volume ~/samus/bare-data/php:/usr/local/etc/php/php.ini \
--volume ~/samus/bare-data/www:/var/www/html:rw \
docker.io/library/php:7.4-fpm-alpine

最后是nginx:

podman run -ti \
--name nginx \
--pod webservice \
--volume ~/samus/bare-data/nginx:/etc/nginx/conf.d:ro \
--volume ~/samus/bare-data/www:/var/www/html \
docker.io/library/nginx:alpine

当我这样做时,PHP告诉我:

[08-Sep-2021 18:05:46] NOTICE: fpm is running, pid 1
[08-Sep-2021 18:05:46] NOTICE: ready to handle connections

关于nginx:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/09/08 18:05:52 [notice] 1#1: using the "epoll" event method
2021/09/08 18:05:52 [notice] 1#1: nginx/1.21.1
2021/09/08 18:05:52 [notice] 1#1: built by gcc 10.3.1 20210424 (Alpine 10.3.1_git20210424) 
2021/09/08 18:05:52 [notice] 1#1: OS: Linux 5.13.13-200.fc34.x86_64
2021/09/08 18:05:52 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 524288:524288
2021/09/08 18:05:52 [notice] 1#1: start worker processes
2021/09/08 18:05:52 [notice] 1#1: start worker process 17
2021/09/08 18:05:52 [notice] 1#1: start worker process 18
2021/09/08 18:05:52 [notice] 1#1: start worker process 19
2021/09/08 18:05:52 [notice] 1#1: start worker process 20
2021/09/08 18:05:52 [notice] 1#1: start worker process 21
2021/09/08 18:05:52 [notice] 1#1: start worker process 22
2021/09/08 18:05:52 [notice] 1#1: start worker process 23
2021/09/08 18:05:52 [notice] 1#1: start worker process 24

这里,如果我执行podman ps -a,我会得到以下结果:

CONTAINER ID  IMAGE                                 COMMAND               CREATED         STATUS                        PORTS                 NAMES
e63300d78306  k8s.gcr.io/pause:3.5                                        23 minutes ago  Up 23 minutes ago             0.0.0.0:8080->80/tcp  0bb2d4aa79a9-infra
aca134de2fb3  docker.io/library/php:7.4-fpm-alpine  php-fpm               23 minutes ago  Up 23 minutes ago             0.0.0.0:8080->80/tcp  php7
f7b19cc296ee  docker.io/library/nginx:alpine        nginx -g daemon o...  23 minutes ago  Up 23 minutes ago             0.0.0.0:8080->80/tcp  nginx

127.0.0.1:8080给予我The connection was reset
在这里,我假设这是不正常的,没有9000端口共享的PHP。
但我不知道为什么。
我试图将端口添加到我的pod(podman pod create --name webservice -p 8080:80 -p 9000:9000),但除了到处都是0.0.0.0:9000->9000/tcp之外,没有什么新的。
我的nginx配置文件(存储在~/samus/bare-data/nginx/podman-nginx-confs中:

server {
    listen 80;
    server_name localhost;
    root /var/www/html;

    location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
    }

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

    location ~ /\.ht {
        deny all;
    }
}
h43kikqp

h43kikqp1#

不需要为pod指定端口9000。尝试将nginx.conf中的这一行更改为:

fastcgi_pass    localhost:9000;

fastcgi_pass    php7:9000;

不管怎么说,答案是晚了,但它可能会帮助用户解决同样的问题。

p4rjhz4m

p4rjhz4m2#

我知道这是一个近2年的问题,但我挣扎了2天,我想通了最近。
如果你在容器(/etc/nginx/nginx.conf)上检查nginx的配置,你会看到它只包含来自/etc/nginx/conf.d/的文件,如果文件扩展名是conf

include /etc/nginx/conf.d/*.conf

因此,将~/samus/bare-data/nginx/podman-nginx-confs重命名为~/samus/bare-data/nginx/podman-nginx-confs.conf,它应该可以工作。
另外,fastcgi_pass不关心您使用的是localhost还是php7。两者都解析为127.0.0.1

相关问题