gpt4 book ai didi

php - 使用 docker-compose 为 php 设置 redis session 处理程序

转载 作者:可可西里 更新时间:2023-11-01 11:12:50 26 4
gpt4 key购买 nike

我认为 redis 会在 redis conf 中绑定(bind)到我的 php 容器,但它失败了:

# Creating Server TCP listening socket phpfpm:6379: bind: Address not available

如果我执行 localhost, session 缓存将无法正常工作。我假设是因为 redis 服务器拒绝了连接。我正在寻找 redis.conf 文件和 php.ini 文件中需要的内容。这是我认为应该是这样的:

php.ini

session.save_handler = redis
session.save_path = "tcp://redis:6379"

redis.conf

bind localhost phpfpm

最佳答案

不知道我是否理解你的问题...

当我遇到网络问题时,我遇到了这种情况,你能举例说明你的 .YML 配置吗?

php:
image: php:7.1-fpm-alpine
#build: php
networks:
- internal_network
volumes:
- ../html:/var/www/html
restart: always
redis:
image: redis:4-alpine
environment:
#- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_PASSWORD=YOUR_REDIS_PASSWORD
command: redis-server --appendonly yes
volumes:
- ../data/redis:/data
networks:
- internal_network
nginx:
image: nginx:1-alpine
ports: #only if traefik is disabled
- 80:80 #only if traefik is disabled
volumes:
- /etc/localtime:/etc/localtime:ro
- ./nginx/conf.d:/etc/nginx/conf.d
- ../html:/var/www/html
networks:
- internal_network
- external_network

扩展是否已安装?你使用构建命令吗?

./php/Dockerfile

FROM php:7.1-fpm-alpine

RUN echo http://dl.alpinelinux.org/alpine/latest-stable/community/ >> /etc/apk/repositories \
&& apk add --no-cache shadow curl vim zlib-dev autoconf g++ make re2c \
&& pecl install -o -f redis \
&& docker-php-ext-enable redis.so \
&& pecl clear-cache

您不需要任何其他东西。你的 redis 必须在 docker 网络中,不能暴露在互联网上

Link to conf

By default, if no "bind" configuration directive is specified, Redis listens for connections from all the network interfaces available on the server. It is possible to listen to just one or multiple selected interfaces using the "bind" configuration directive, followed by one or more IP addresses.

Examples:

bind 192.168.1.100 10.0.0.1 bind 127.0.0.1 ::1

~~~ WARNING ~~~ If the computer running Redis is directly exposed to the internet, binding to all the interfaces is dangerous and will expose the instance to everybody on the internet. So by default we uncomment the following bind directive, that will force Redis to listen only into the IPv4 lookback interface address (this means Redis will be able to accept connections only from clients running into the same computer it is running).

IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES JUST COMMENT THE FOLLOWING LINE. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 127.0.0.1

关于php - 使用 docker-compose 为 php 设置 redis session 处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49078029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com