如何使用Apache和Django(以及Docker)配置ProxyPass?
我正在尝试构建一个本地docker容器,使其具有Django 2/Python 3.7、Apache 2.4和MySql 5.7映像。我在配置Apache代理以与Django实例正确交互时遇到问题。我的apache/my-vhosts.conf文件如下如何使用Apache和Django(以及Docker)配置ProxyPass?,django,apache,docker,proxypass,django-2.0,Django,Apache,Docker,Proxypass,Django 2.0,我正在尝试构建一个本地docker容器,使其具有Django 2/Python 3.7、Apache 2.4和MySql 5.7映像。我在配置Apache代理以与Django实例正确交互时遇到问题。我的apache/my-vhosts.conf文件如下 <VirtualHost *:80> ServerName maps.example.com ProxyPreserveHost On ProxyPass / http://127.0.0.1/ Pr
<VirtualHost *:80>
ServerName maps.example.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1/
ProxyPassReverse / http://127.0.0.1/
</VirtualHost>
我的整个docker-compose.yml文件看起来像
version: '3'
services:
web:
restart: always
build: ./web
ports: # to access the container from outside
- "8000:8000"
environment:
DEBUG: 'true'
command: /usr/local/bin/gunicorn maps.wsgi:application -w 2 -b :8000
apache:
restart: always
build: ./apache/
ports:
- "80:80"
#volumes:
# - web-static:/www/static
links:
- web:web
mysql:
restart: always
image: mysql:5.7
environment:
MYSQL_DATABASE: 'maps_data'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'chicommons'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
ports:
- "3406:3406"
volumes:
- my-db:/var/lib/mysql
volumes:
my-db:
不幸的是,当我用“docker compose up”启动所有程序时,我对代理服务器的“请求”会随着“代理服务器收到来自上游服务器的无效响应”而终止。在docker compose输出中,我看到
apache_1 | [Sun Feb 09 21:07:37.521332 2020] [proxy:error] [pid 11:tid 140081943791360] [client 127.0.0.1:35934] AH00898: Error reading from remote server returned by /
apache_1 | 127.0.0.1 - - [09/Feb/2020:21:06:37 +0000] "GET / HTTP/1.1" 502 341
我认为问题在于apache/my-vhosts.conf文件。 配置ProxyPass
/
至http://127.0.0.1/
,这意味着您要代理到apache
服务的本地主机,而不是web
服务或主机上。
要代理传递到web,请改用此my-vhosts.conf配置文件:
<VirtualHost *:80>
ServerName maps.example.com
ProxyPreserveHost On
ProxyPass / http://web:8000/
ProxyPassReverse / http://web:8000/
</VirtualHost>
ServerName maps.example.com
代理主机
ProxyPass/http://web:8000/
ProxyPassReverse/http://web:8000/
不要使用apache中的127.0.0.1
,而是使用web
这是一个赢家。谢谢,所以muchIt不适合我。我使用此配置时出现内部服务器错误
<VirtualHost *:80>
ServerName maps.example.com
ProxyPreserveHost On
ProxyPass / http://web:8000/
ProxyPassReverse / http://web:8000/
</VirtualHost>