Ubuntu 22.04上安装了Apache 2.4的Django 4最初正在加载,但随后停止工作,直到Apache重新启动

agyaoht7  于 2023-01-31  发布在  Apache
关注(0)|答案(1)|浏览(225)

我在我的Synology NAS的虚拟机上的Ubuntu 22.04 Server示例上使用python 3.10部署了我的Django 4项目和SQLITE3 DB。我正在使用WSGI模块,据我所知,这是唯一的方法,对吗?我的Synology NAS有Intel赛扬进程和10 GB RAM(2核和6 GB可用于虚拟机,我也先用4 GB试了试)
现在,我管理后,我的网站可以调用并显示,我面临的问题是,我可以调用任何页面,最初我想,它显示为预期,但然后浏览器选项卡通过一个移动圆圈表示,仍然有东西正在加载,我不能导航到我的应用程序中的任何其他URL。甚至语言显示正确取决于浏览器语言。在我重新启动Apache之后,下一个页面也会加载。这样做我甚至可以在2个步骤中登录到管理用户界面,所以数据库显然是可以访问的。
同时,将Apache服务器的日志级别提高到trace 1,现在可以看到,5分钟后,进程被终止并因任何原因重新启动,但至少我的环境变量被正确加载:这一点我可以通过使用print语句在日志中显示它们来看到。我还授予了我的数据库明确的完整权限für:www-data,因为在我看来,应用程序或Apache可能在写入数据库时存在问题。下面是错误日志和Myebsite.log的摘录。是的,我是这样命名的:-)
所以我希望这里有人能给我正确的线索,让它运行起来。提前谢谢你!

从我的网站日志中提取

在20:43到20:48之间,没有任何事情发生,直到进程停止。

[Thu Jan 26 20:43:24.001088 2023] [deflate:trace1] [pid 834] mod_deflate.c(734): [client 192.168.175.42:51447] token: 'gzip' - q: ''
[Thu Jan 26 20:43:24.158541 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158605 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158822 2023] [deflate:trace1] [pid 832] mod_deflate.c(734): [client 192.168.175.42:51449] token: 'gzip' - q: '', referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.167348 2023] [deflate:debug] [pid 832] mod_deflate.c(869): [client 192.168.175.42:51449] AH01384: Zlib: Compressed 153402 to 22635 : URL /static/homepage/bootstrap.min.css, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:43:24 +0000] "GET /static/homepage/bootstrap.min.css HTTP/1.1" 200 22993 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:23.835110 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Daemon process deadlock timer expired, stopping process 'MyWebsite'.
[Thu Jan 26 20:48:23.835355 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Shutdown requested 'MyWebsite'.
[Thu Jan 26 20:48:24.023436 2023] [wsgi:error] [pid 834] (70007)The timeout specified has expired: [client 192.168.175.42:51447] mod_wsgi (pid=834): Failed to proxy response from daemon.
[Thu Jan 26 20:48:24.023582 2023] [deflate:debug] [pid 834] mod_deflate.c(869): [client 192.168.175.42:51447] AH01384: Zlib: Compressed 9409 to 3096 : URL /
192.168.175.42 - - [26/Jan/2023:20:43:13 +0000] "GET / HTTP/1.1" 200 3562 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:24.087213 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:48:24.087306 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:48:24 +0000] "GET /static/homepage/minion_logo.png HTTP/1.1" 304 249 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:28.836028 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Aborting process 'MyWebsite'.
[Thu Jan 26 20:48:28.836241 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Exiting process 'MyWebsite'.
[Thu Jan 26 20:48:29.768996 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Attach interpreter ''.
[Thu Jan 26 20:48:29.791601 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Adding '/var/www/MyWebsite/MyWebsite' to path.
[Thu Jan 26 20:48:29.793603 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 0 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794397 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 1 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794441 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 4 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794595 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 3 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794677 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 2 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794863 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 5 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795137 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 6 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795248 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 7 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795994 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 14 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796116 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 13 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796215 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 12 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796293 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 9 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796373 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 11 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796496 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 10 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796591 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 8 in daemon process 'MyWebsite'.

提取错误日志

[Thu Jan 26 20:42:52.685411 2023] [watchdog:debug] [pid 828] mod_watchdog.c(445): AH010033: Watchdog: Running with WatchdogInterval 1000ms
[Thu Jan 26 20:42:52.685641 2023] [watchdog:debug] [pid 828] mod_watchdog.c(454): AH02974: Watchdog: found parent providers.
[Thu Jan 26 20:42:52.685661 2023] [watchdog:debug] [pid 828] mod_watchdog.c(500): AH02977: Watchdog: found child providers.
[Thu Jan 26 20:42:52.685678 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_singleton_).
[Thu Jan 26 20:42:52.685694 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_default_).
[Thu Jan 26 20:42:52.686259 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8512): mod_wsgi (pid=828): Socket for 'MyWebsite' is '/var/run/apache2/wsgi.828.0.1.sock'.
[Thu Jan 26 20:42:52.686405 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8581): mod_wsgi (pid=828): Listen backlog for socket '/var/run/apache2/wsgi.828.0.1.sock' is '100'.
[Thu Jan 26 20:42:52.690541 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:42:52.705603 2023] [mpm_prefork:notice] [pid 828] AH00163: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Thu Jan 26 20:42:52.705648 2023] [mpm_prefork:info] [pid 828] AH00164: Server built: 2022-09-30T04:09:50
[Thu Jan 26 20:42:52.705701 2023] [core:notice] [pid 828] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jan 26 20:42:52.705719 2023] [core:debug] [pid 828] log.c(1570): AH02639: Using SO_REUSEPORT: yes (1)
[Thu Jan 26 20:42:52.705736 2023] [mpm_prefork:debug] [pid 828] prefork.c(953): AH00165: Accept mutex: none (default: pthread)
[Thu Jan 26 20:42:52.706664 2023] [watchdog:debug] [pid 831] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.707440 2023] [watchdog:debug] [pid 832] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.712781 2023] [watchdog:debug] [pid 834] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.713025 2023] [watchdog:debug] [pid 833] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.718786 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Initializing Python.
[Thu Jan 26 20:42:52.719577 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:42:52.719790 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Initializing Python.
[Thu Jan 26 20:42:52.720365 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Initializing Python.
[Thu Jan 26 20:42:52.720460 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Initializing Python.
[Thu Jan 26 20:42:52.721846 2023] [watchdog:debug] [pid 830] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.722049 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Initializing Python.
[Thu Jan 26 20:42:52.796422 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Initializing Python.
[Thu Jan 26 20:42:53.972677 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Attach interpreter ''.
[Thu Jan 26 20:42:53.999176 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Attach interpreter ''.
[Thu Jan 26 20:42:54.057680 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Attach interpreter ''.
[Thu Jan 26 20:42:54.071090 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Attach interpreter ''.
[Thu Jan 26 20:42:54.113752 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Attach interpreter ''.
[Thu Jan 26 20:43:14.732936 2023] [watchdog:debug] [pid 1127] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:14.733171 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Initializing Python.
[Thu Jan 26 20:43:14.792782 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Attach interpreter ''.
[Thu Jan 26 20:43:24.421107 2023] [watchdog:debug] [pid 1128] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:24.421327 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Initializing Python.
[Thu Jan 26 20:43:24.485083 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Attach interpreter ''.
[Thu Jan 26 20:48:29.725192 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has died, deregister and restart it.
[Thu Jan 26 20:48:29.725334 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has been deregistered and will no longer be monitored.
[Thu Jan 26 20:48:29.726543 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:48:29.730090 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:48:29.730296 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Initializing Python.

Apache.conf设置(我删除了所有注解行)

DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 1
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel trace1

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

我的网站.conf

VirtualHost *:80>

        ServerAdmin admin@MyWebsite.com
        ServerName MyWebsite.com
        ServerAlias www.MyWebsite.com

        DocumentRoot /var/www/MyWebsite/MyWebsite/

        ErrorLog ${APACHE_LOG_DIR}/MyWebsite.log
        CustomLog ${APACHE_LOG_DIR}/MyWebsite.log combined

        Alias /static /var/www/MyWebsite/MyWebsite/static
        <Directory /var/www/MyWebsite/MyWebsite/static>
                Require all granted
        </Directory>

        Alias /media /var/www/MyWebsite/MyWebsite/media
        <Directory /var/www/MyWebsite/MyWebsite/media>
                Require all granted
         </Directory>

        <Directory /var/www/MyWebsite/MyWebsite/MyWebsite>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess MyWebsite python-path=/var/www/MyWebsite/MyWebsite python-home=/var/www/MyWebsite/MyWebsite/venv
        WSGIProcessGroup MyWebsite
        WSGIScriptAlias / /var/www/MyWebsite/MyWebsite/MyWebsite/wsgi.py

</VirtualHost>

WSGI.py

"""
WSGI config for MyWebsite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyWebsite.settings')

application = get_wsgi_application()

from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)

VENV中的软件包列表(python版本:Python 3.10.6)

Package           Version
----------------- -------
asgiref           3.6.0
autopep8          2.0.1
Django            4.1.4
django-countries  7.5
pip               22.0.2
pycodestyle       2.10.0
python-dotenv     0.21.0
setuptools        59.6.0
sqlparse          0.4.3
tomli             2.0.1
typing_extensions 4.4.0
tzdata            2022.7
eimct9ow

eimct9ow1#

已经有一段时间了,但是...这是我刚刚从一个基于Ubuntu映像的容器中采取的步骤:

> apt-get install apache2
> apt-get install apache2-dev
> ...env/bin/activate                   # activate virt env
> apt-get install mod_wsgi

> mod_wsgi-express module-config        # run the command and copy 2 output lines (see below example) from terminal to apache config file (not inside vhost/host)

something like:
LoadModule wsgi_module "/var/www/project/env/lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/project/env"

the rest seems ok in your vhost conf etc.

相关问题