英文:
How to use Apache httpd as a reverse proxy with Docker Compose and the "whoami" container?
问题
以下是翻译好的部分:
我正在尝试设置一个包含Apache httpd服务器和一个"whoami"容器的Docker Compose环境,并且我想要使用Apache httpd服务器作为反向代理来将请求路由到"whoami"容器。
这是我的docker-compose.yml文件:
version: '3'
services:
httpd:
image: httpd:latest
ports:
- "80:80"
volumes:
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
whoami:
image: containous/whoami
ports:
- "8080:80"
这是我的httpd.conf文件:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
ServerName 127.0.0.1
Listen *:80
<Proxy balancer://whoami>
BalancerMember http://whoami-replica-1:80
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://whoami
ProxyPassReverse / balancer://whoami
当我运行docker-compose up时,我可以访问"http://localhost:8080"的"whoami"容器,但是当我尝试访问"http://localhost"的Apache httpd服务器时,我得到httpd退出并没有任何日志。
我做错了什么?我如何配置Apache httpd来充当Docker Compose中"whoami"容器的反向代理?
英文:
I'm trying to set up a Docker Compose environment that includes an Apache httpd server and a "whoami" container, and I want to use the Apache httpd server as a reverse proxy to route requests to the "whoami" container.
Here's my docker-compose.yml file:
version: '3'
services:
httpd:
image: httpd:latest
ports:
- "80:80"
volumes:
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
whoami:
image: containous/whoami
ports:
- "8080:80"
And here's my httpd.conf file:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
ServerName 127.0.0.1
Listen *:80
<Proxy balancer://whoami>
BalancerMember http://whoami-replica-1:80
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://whoami
ProxyPassReverse / balancer://whoami
When I run docker-compose up, I can access the "whoami" container at http://localhost:8080, but when I try to access the Apache httpd server at http://localhost, I get httpd exited without any logs.
What am I doing wrong? How can I configure Apache httpd to act as a reverse proxy for the "whoami" container in Docker Compose?
答案1
得分: 1
httpd
正在退出,因为您的 httpd.conf
是无效的。您正在替换默认的 httpd.conf
,这意味着您需要注意加载适当的安全模块(例如,mod_unixd
)等必需配置。
更好的方法是从 httpd 镜像复制 httpd.conf
:
docker run httpd:latest cat /usr/local/apache2/conf/httpd.conf > httpd.conf
然后根据您的需求进行修改。
我只能通过在本地使用 strace
控制 Apache 运行来确定问题:
$ sudo strace -e trace=write -s 1024 httpd -DFOREGROUND -f $PWD/httpd.conf
write(2, "[Tue Jun 06 06:00:33.356982 2023] [core:crit] [pid 755528:tid 755528] AH00136: Server MUST relinquish startup privileges before accepting connections. Please ensure mod_unixd or other system security module is loaded.\n", 219) = 219
write(2, "AH00016: Configuration Failed\n", 30) = 30
+++ exited with 1 +++
搜索这个错误信息会导向到 此2.2到2.4升级文档,其中提到了所需的 mod_unixd
模块。
我无法想出任何 httpd
的命令行调用能够以有用的方式生成此错误。
英文:
httpd
is exiting because your httpd.conf
is invalid. You're replacing the default httpd.conf
, which means you need to take care of mandatory configuration like loading an appropriate security module (e.g., mod_unixd
).
A better approach is to copy the httpd.conf
from the httpd image:
docker run httpd:latest cat /usr/local/apache2/conf/httpd.conf > httpd.conf
And then modify it to meet your needs.
I was only able to determine the problem by running Apache locally under control of strace
:
$ sudo strace -e trace=write -s 1024 httpd -DFOREGROUND -f $PWD/httpd.conf
write(2, "[Tue Jun 06 06:00:33.356982 2023] [core:crit] [pid 755528:tid 755528] AH00136: Server MUST relinquish startup privileges before accepting connections. Please ensure mod_unixd or other system security module is loaded.\n", 219) = 219
write(2, "AH00016: Configuration Failed\n", 30) = 30
+++ exited with 1 +++
Searching for that error message leads to this 2.2 to 2.4 upgrade documentation which among other things mentions the required mod_unixd
module.
I was not able to come up with any command line invocation of httpd
that would get it to emit this error in a useful fashion.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论