【发布时间】:2023-03-10 01:21:01
【问题描述】:
我正在尝试使用 apache2 服务器在 Docker 中托管 Django 项目。我正在手动启动 apache 服务器并能够访问默认站点。但是,当我配置 000-default.config 文件时,我收到错误您没有权限访问此服务器上的 /。
这是我的 000-default.config 文件
<VirtualHost *:8000>
DocumentRoot /code/demo
WSGIScriptAlias / /code/demo/app/wsgi.py
<Directory "/code/demo/backup">
Require all granted
</Directory>
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
这是我的 Dockerfile
FROM ubuntu
MAINTAINER kketan@somemail.com
RUN apt-get update && apt-get -y --force-yes install build-essential
RUN apt-get -y --force-yes install python python-pip python-dev
RUN apt-get -y --force-yes install libffi-dev libssl-dev
RUN apt-get install -y --force-yes libmysqlclient-dev
RUN mkdir /code
ADD evn_packages.txt /code
ADD python_packages.txt /code
RUN apt-get install -y apache2
RUN apt-get install -y mariadb-server
RUN pip install --upgrade pip
RUN pip install -r python_packages.txt
RUN apt-get install -y vim
ADD django /code
EXPOSE 8000
RUN apt-get install -y libapache2-mod-wsgi
我正在从上面显示的同一目录中导入 Django 项目。即使使用默认的 Django 服务器也能够运行项目,但无法在浏览器中访问它。我还将端口监听更改为 8000,因为它在默认端口 80 上不起作用。
我是 docker 新手,我是否在 Dockerfile 中遗漏并授予权限?您还可以分享一些如何在 Docker 中使用 apache2 托管 Django 项目的链接,因为我无法在网上找到好的内容。
【问题讨论】:
标签: django apache docker mod-wsgi dockerfile