【发布时间】:2021-07-08 04:07:16
【问题描述】:
所以我一直在尝试在容器上使用 apache 对我的 Django 应用程序进行 docker 化,但我不断收到此错误
Invalid command 'WSGIProcessGroup', perhaps misspelled or defined by a module not included in the server configuration
我尝试用 apt 和 pip 安装 mod_wsgi 但结果还是一样
这是我的 Dockerfile
FROM httpd:2.4
ADD ./requirements.txt ./
RUN apt-get update \
&& apt-get install -y \
python3-pip python3-venv \
libapr1 libapr1-dev \
libaprutil1-dev \
libapache2-mod-wsgi \
&& python3 -m venv /.cp \
&& /.cp/bin/pip install --no-cache-dir -r requirements.txt \
&& rm -rf /var/lib/apt/lists/*
requirements.txt
django
mod-wsgi
psycopg2-binary
djangorestframework
markdown
django-filter
我的自定义虚拟主机文件
<VirtualHost *:80>
serverAdmin svenikia@taskmaster.com
DocumentRoot "/usr/local/apache2/htdocs/webapp"
Servername www.webapp.io
ServerAlias webapp.io
ErrorLog "/var/log/apache2/error.log"
CustomLog "/var/log/apache2/access.log" combined
Alias /static /capstone/static
<Directory "/usr/local/apache2/htdocs/webapp/static">
Require all granted
AllowOverride None
</Directory>
<Directory "/usr/local/apache2/htdocs/webapp/webapp">
<Files wsgi.py>
AllowOverride None
Require all granted
</Files>
</Directory>
WSGIProcessGroup webapp_project
WSGIDaemonProcess webapp_project python-path=/webapp python-home=/.env
WSGIScriptAlias / /usr/local/apache2/htdocs/webapp/webapp/wsgi.py
</VirtualHost>
这是我的 docker compose 文件
version: '2'
services:
postgres:
image: postgres:13.1-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: parking
restart: always
container_name: db
apache:
build : ./Django
image: web:1.0
container_name: web
ports:
- "8080:80"
volumes:
- ./my-httpd.conf:/usr/local/apache2/conf/httpd.conf
- ./Django/web.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf
- ./Django/web:/usr/local/apache2/htdocs/my-web
networks:
default:
external:
name: network
起初我最初的想法是拥有 3 个容器,一个用于 postgres,第二个用于 django,第三个用于 apache。但是在多次尝试失败后,我只使用了 2 个容器,一个用于 postgres,另一个用于生成 virtualenv、django app 和 apache。任何帮助都会很棒,谢谢
【问题讨论】:
标签: django docker apache docker-compose