有这样一个Apache + WSGI Django Docker 的组合。当容器启动时,默认的 Apache 页面正常打开。但是,当您使用 Django 应用程序访问某些页面时,它无法打开,并且日志中出现错误:This is a log in the container
root@828dcbc18f43:/# tail -f /var/log/apache2/error.log
mod_wsgi (pid=9): Failed to exec Python script file '/home/test/app1/backend/otu_it/wsgi.py'.
mod_wsgi (pid=9): Exception occurred processing WSGI script '/home/test/app1/backend/otu_it/wsgi.py'.
Traceback (most recent call last):
File "/home/test/app1/backend/otu_it/wsgi.py", line 20, in <module>
application = get_wsgi_application()
File "/home/test/app1/venv/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/test/app1/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/test/app1/venv/lib/python3.8/site-packages/django/apps/registry.py", line 83, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
这是 Django 应用程序的 Apache 配置文件:
WSGIPythonHome /home/test/app1/venv
WSGIPythonPath /home/test/app1/backend
<VirtualHost *:80/api/user>
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/test/app1/backend/
WSGIScriptAlias / /home/test/app1/backend/otu_it/wsgi.py
# WSGIPythonHome /home/test/app1/venv
# WSGIPythonPath /home/test/app1/backend
<Directory /home/test/app1/backend/otu_it/>
## NEW
Require all granted
<Files wsgi.py>
Require all granted
</Files>
# Order allow,deny
# Allow from all
</Directory>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/cert.crt
SSLCertificateKeyFile /etc/apache2/ssl/cert.key
ServerAdmin webmaster@localhost
DocumentRoot /home/test/app1/backend/
WSGIScriptAlias / /home/test/app1/backend/otu_it/wsgi.py
# WSGIPythonHome /home/test/app1/venv
# WSGIPythonPath /home/test/app1/backend
<Directory /home/test/app1/backend/otu_it/>
<Files wsgi.py>
Require all granted
</Files>
# Order allow,deny
# Allow from all
</Directory>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
也许我错误地连接了 Django 的虚拟环境。我已经尝试了很多 - 没有任何帮助。可能是什么问题呢?PS - 在容器之外,一切都可以使用这些配置,没有问题。
经过更仔细的研究日志后,我发现了这些条目:
接下来我安装了附加模块
一切顺利。