gpt4 book ai didi

php - ProxyPassMatch到fcgi的平衡器不起作用

转载 作者:行者123 更新时间:2023-12-02 19:21:49 24 4
gpt4 key购买 nike

我有一个docker-compose安装程序。基本上有3种服务:php-fpm,apache服务器和mysql。

我的docker-compose文件在这种情况下应该可以使用(可以跳过):

version: "3"

services:
php-fpm:
build:
context: ./bin/php-fpm
args:
SITE_HOSTNAME: ${SITE_HOSTNAME-example.com}
SITE_TITLE: ${SITE_TITLE-WPBuilder}
DOCKER_PASSWORD: ${DOCKER_PASSWORD-docker}
MYSQL_USER_NAME: ${MYSQL_USER_NAME-wp}
MYSQL_USER_PASSWORD: ${MYSQL_USER_PASSWORD-wppass}
ADMIN_USER_NAME: ${ADMIN_USER_NAME-admin}
ADMIN_USER_PASSWORD: ${ADMIN_USER_PASSWORD-adminpass}
ADMIN_EMAIL: ${ADMIN_EMAIL-admin@example.com}
depends_on:
- mysql
networks:
- wp_network
volumes:
- "source_code:/srv/www/${SITE_HOSTNAME-example.com}"
webserver:
build:
context: ./bin/webserver
args:
SITE_HOSTNAME: ${SITE_HOSTNAME-example.com}
container_name: 'wp_server'
networks:
- wp_network
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
- mysql
volumes:
- "source_code:/srv/www/${SITE_HOSTNAME-example.com}"
- "${APACHE_LOG_DIR-./logs/apache2}:/usr/local/apache2/logs/${SITE_HOSTNAME-example.com}"
mysql:
build:
context: ./bin/mysql
args:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD-password}
MYSQL_USER_NAME: ${MYSQL_USER_NAME-wp}
MYSQL_USER_PASSWORD: ${MYSQL_USER_PASSWORD-wppass}
container_name: 'wp_db'
networks:
- wp_network
ports:
- "3306:3306"
volumes:
- "db_volume:/var/lib/mysql"
- "${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD-password}
networks:
wp_network:
volumes:
db_volume:
source_code:

我运行它来启动服务,尤其是使用4个php-fpm容器:
docker-compose up --scale php-fpm=4

我在浏览器中输入本地主机的主机名,它只返回“找不到文件”。在白色屏幕上。

apache的屏幕日志:
wp_server    | 192.168.144.1 - - [28/Nov/2019:17:58:37 +0000] "GET / HTTP/1.1" 404 16

以及第一个php-fpm容器的访问日志:
192.168.144.5 -  28/Nov/2019:17:58:37 +0000 "GET " 404 - 0.748 2048 0.00%

最后是我的Apache site.conf:
ServerName hostname

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
LoadModule rewrite_module /usr/local/apache2/modules/mod_rewrite.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

<VirtualHost *:80>
# Proxy .php requests to port 9000 of the php-fpm container(s)
ProxyPassMatch "^/(.*\.php(/.*)?)$" "balancer://cluster/"
<Proxy "balancer://cluster/">
BalancerMember fcgi://wpbuilder_php-fpm_1:9000/srv/www/hostname/$1
BalancerMember fcgi://wpbuilder_php-fpm_2:9000/srv/www/hostname/$1
BalancerMember fcgi://wpbuilder_php-fpm_3:9000/srv/www/hostname/$1
BalancerMember fcgi://wpbuilder_php-fpm_4:9000/srv/www/hostname/$1
ProxySet lbmethod=byrequests
</Proxy>

DocumentRoot /srv/www/hostname/
<Directory /srv/www/hostname/>
DirectoryIndex index.php
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>

# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
CustomLog logs/hostname/hostname-access_log common
ErrorLog /proc/self/fd/2
ErrorLog logs/hostname/hostname-error_log
</VirtualHost>

有人可以阐明这一点吗,这已经花了我整天的时间了……谢谢!

最佳答案

解决了:

apache站点虚拟主机配置:

ServerName hostname

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
LoadModule rewrite_module /usr/local/apache2/modules/mod_rewrite.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so

<VirtualHost *:80>
# Proxy .php requests to port 9000 of the php-fpm container(s)
<Proxy balancer://cluster>
BalancerMember fcgi://wpbuilder_php-fpm_1:9000
BalancerMember fcgi://wpbuilder_php-fpm_2:9000
BalancerMember fcgi://wpbuilder_php-fpm_3:9000
BalancerMember fcgi://wpbuilder_php-fpm_4:9000
ProxySet lbmethod=byrequests
</Proxy>

DocumentRoot /srv/www/hostname
<Directory /srv/www/hostname>
DirectoryIndex index.php
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
<FilesMatch \.php$>
SetHandler proxy:balancer://cluster
</FilesMatch>
</Directory>

# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
CustomLog logs/hostname/hostname-access_log common
ErrorLog /proc/self/fd/2
ErrorLog logs/hostname/hostname-error_log
</VirtualHost>

关键是使用FilesMatch而不是ProxyPassMatch方法。

关于php - ProxyPassMatch到fcgi的平衡器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59094459/

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