【发布时间】:2022-01-07 21:49:32
【问题描述】:
我无法通过触摸位于我的 django 应用程序根目录/应用程序名称中的 wsgi.py 脚本来重新加载 django 模板。
脚本和项目位于/var/www下,所以我需要sudo来执行touch。
我正在运行生产 apache2 服务器,该服务器运行 django 网站,mod_wsgi 处于守护程序模式。我可以收集静态数据并进行迁移,访问数据库(没有权限问题)。我还可以在设置中更改 DEBUG 标志。如果我触摸 wsgi.py,它将按预期将生产站点置于调试状态,但未加载 html。同样,我可以更新静态文件、收集静态文件或修改底层模型并实时查看更改。同样,我可以使用注释代码来检索 swerver 正在运行的守护程序模式。它只是导致问题的模板。设置文件、wsgi.py、statics 和 python 脚本按预期响应。
有人知道如何调试吗?
virtualenv python3.8.12 apache2.4 为python3.8.12编译的mod_wsgi
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../app/")))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mb.settings')
application = get_wsgi_application()
#def application(environ, start_response):
# status = '200 OK'
# if not environ['mod_wsgi.process_group']:
# output = u'EMBEDDED MODE'
# else:
# output = u'DAEMON MODE'
# response_headers = [('Content-Type', 'text/plain'),
# ('Content-Length', str(len(output)))]
# start_response(status, response_headers)
# return [output.encode('UTF-8')]
apache2 站点配置
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName app
ServerAdmin webmaster@localhost
ServerName ------removed for posting-----
ServerAlias -----removed for posting------
DocumentRoot /var/www/vhosts/mb
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/vhosts/mb>
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /static /var/www/vhosts/mb/static
<Directory /var/www/vhosts/mb/static>
Require all granted
</Directory>
<Directory /var/www/vhosts/mb/mb>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mb python-path=/var/www/vhosts/mb python-home=/var/www/vhosts/mb/pyenv
WSGIProcessGroup mb
WSGIScriptAlias / /var/www/vhosts/mb/mb/wsgi.py
WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
【问题讨论】:
标签: python-3.x django apache2 virtualenv mod-wsgi