【发布时间】:2019-12-09 16:40:36
【问题描述】:
所以基本上,我想在我的国家/地区托管部署 django (wagtail) 应用程序。这是我所做的:
- 我使用 FTP 将我的项目文件复制到 /home/ketohubp/KetoHub.pl。
- 我创建并输入了 venv (
source venv/bin/activate)。 - 我尝试使用以下命令部署应用程序:
uwsgi --http 127.0.0.1:8054 --chdir /home/ketohubp/KetoHub.pl --wsgi-file /home/ketohubp/KetoHub.pl/wsgi.py --master --processes 1 --workers 1 --threads 1 --daemonize=/home/ketohubp/KetoHub.pl/log.txt
- 我检查了是否安装了 django:
(venv) ketohubp@hs7:~$ django-admin version 2.2.8
- 我尝试使用
fuser -k 8054/tcp杀死并重新生成 uwsgi 进程 - 我检查了 log.txt 包含的内容:
*** Starting uWSGI 2.0.18 (64bit) on [Mon Dec 9 17:37:19 2019] ***
compiled with version: 6.3.0 20170516 on 21 November 2019 19:38:29
os: Linux-4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19)
nodename: hs7.linux.pl
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /home/ketohubp/KetoHub.pl
detected binary path: /home/ketohubp/venv/bin/uwsgi
chdir() to /home/ketohubp/KetoHub.pl
your processes number limit is 256771
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 127.0.0.1:8054 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:37743 (port auto-assigned) fd 3
Python version: 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]
Python main interpreter initialized at 0x55be3db1eb40
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145840 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
failed to open python file /home/ketohubp/KetoHub.pl/wsgi.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 16988)
spawned uWSGI worker 1 (pid: 16989, cores: 1)
spawned uWSGI http 1 (pid: 16990)
- 我联系了托管支持以查看服务器错误:
[Wed Dec 04 20:53:06.200086 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] mod_wsgi (pid=4914): Failed to exec Python script file '/home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/wsgi.py'.
[Wed Dec 04 20:53:06.200171 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] mod_wsgi (pid=4914): Exception occurred processing WSGI script '/home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/wsgi.py'.
[Wed Dec 04 20:53:06.200187 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] Traceback (most recent call last):
[Wed Dec 04 20:53:06.200196 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] File "/home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/wsgi.py", line 12, in <module>
[Wed Dec 04 20:53:06.200222 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] from django.core.wsgi import get_wsgi_application
[Wed Dec 04 20:53:06.200231 2019] [wsgi:error] [pid 4914:tid 140320264152832] [remote 193.239.126.103:49538] ImportError: No module named django.core.wsgi
- 我再次联系主机检查配置文件:
DocumentRoot /home/ketohubp/KetoHub.pl
WSGIScriptAlias / /home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/wsgi.py
WSGIDaemonProcess ketohub.pl processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup ketohub.pl
<directory /home/ketohubp/KetoHub.pl>
SetHandler wsgi-script
AllowOverride all
Require all granted
Options ExecCGI FollowSymlinks
<Files wsgi.py>
Require all granted
</Files>
</directory>
Alias /static/ /home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/static/
<Directory /home/ketohubp/KetoHub.pl/Wagtail_Django_Static_Blog/static>
Require all granted
</Directory>
【问题讨论】:
-
这有点令人困惑。您使用的是 uWSGI 还是 mod_wsgi?以及如何在生产中激活 virtualenv?
-
补充一点:您的错误跟踪(和您的 Apache 配置)显示您正在使用 mod_wsgi,但由于您的 virtualenv 未激活,因此无法正常工作。阅读this,看看如何正确设置
WSGIDaemonProcess(你还没有配置python-path。而且你用mod_wsgi就不需要uwsgi了。 -
@DanielRoseman 我不确定,我是开发运维之类的初学者。但我认为我是 usnig uwsgi,因为我现在是从你那里第一次听说 mod_wsgi,我会读到它。我在生产中激活 virtualenv,就像提供的一样:source venv/bin/activate。
-
@dirkgroten 我用这个应用程序所做的一切都是在 venv 处于活动状态时完成的( (venv) ketohubp@hs7:~$ )。我现在知道 mod_wsgi 是什么了。我阅读了文章,感谢您的帮助,我是否必须要求我的托管管理员将这些行添加到配置中?或者我可以在调用 uwsgi 命令时使用“python-path”和“python-home=/path/to/venv”(有问题提供)。感谢您的帮助。 (顺便说一句,你能解释一下 WSGIDaemonProcess 是做什么的吗?我读到它是推荐的,它在其中运行 django 实例,但我不明白它是什么。谢谢你的时间。)
-
你很困惑。您不能只在 shell 中激活 virtualenv,关闭该会话,然后期望它以某种方式进入一个完全独立的进程。对于不知道什么是 mod_wsgi 的人,您在 Apache 配置中使用了几个 mod_wsgi 指令。虽然我必须说,如果您使用的托管服务提供商需要调用支持以查看日志或修改配置,您应该立即找到其他服务提供商。
标签: python django deployment wsgi