版本列表:
Centos 7 --- django 2.1.7 --- Apache 2.4.6 --- Python 3.6
检查 EDIT 5 以获取最新的错误日志
我能够运行sudo systemctl start httpd
,当我转到url时,我会收到内部服务器错误(底部的日志)
我的文件结构
home
└── user
└── projects
└── myapp
├── app
│ ├── <All Code for Webapp including static dir>
├── env (virtualenv)
├── manage.py
├── new
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── requirements.txt
我希望有人能在我的httpd文件夹下的django.conf中看到错误。希望这些是我正在寻找的端点
编辑:该文件位于这里:/etc/httpd/conf.d/django.conf
django.conf
Alias /static /home/user/projects/myapp/app/static
<Directory /home/user/projects/myapp/app/static>
Require all granted
</Directory>
<Directory /home/user/projects/myapp/new>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess myapp python-path=/home/user/projects/myapp python-home=/home/user/projects/myapp/env
WSGIProcessGroup myapp
WSGIScriptAlias / /home/user/projects/myapp/new/wsgi.py
我不确定这些图标是否指向所有正确的地方,并希望有人可以给我第二眼。
我还没有碰过wsgi.py,想知道我是否在那里缺少任何逻辑。
我的wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'new.settings')
application = get_wsgi_application()
EDIT2 :我能够运行服务器,但收到500个内部服务器错误,当我检查error_logs时,我会得到此
更新的日志
[Mon Mar 11 10:40:39.865611 2019] [core:notice] [pid 9371] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Mar 11 10:40:39.868149 2019] [suexec:notice] [pid 9371] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Mar 11 10:40:39.918015 2019] [auth_digest:notice] [pid 9371] AH01757: generating secret for digest authentication ...
[Mon Mar 11 10:40:39.919681 2019] [lbmethod_heartbeat:notice] [pid 9371] AH02282: No slotmem from mod_heartmonitor
[Mon Mar 11 10:40:39.948303 2019] [mpm_prefork:notice] [pid 9371] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations
[Mon Mar 11 10:40:39.948370 2019] [core:notice] [pid 9371] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Mar 11 10:40:42.878806 2019] [mime_magic:error] [pid 9376] [client ip] AH01512: mod_mime_magic: can't read `/home/user/projects/myapp/new/wsgi.py'
[Mon Mar 11 10:40:42.879459 2019] [mime_magic:error] [pid 9376] [client ip] AH01512: mod_mime_magic: can't read `/home/user/projects/myapp/new/wsgi.py'
[Mon Mar 11 10:40:42.905048 2019] [:error] [pid 9372] (13)Permission denied: [remote ip] mod_wsgi (pid=9372, process='myapp', application='<url>|'): Call to fopen() failed for '/home/user/projects/myapp/new/wsgi.py'
EDIT3
在此日志文件中,当我运行python3.6而不是2.7.5时,它说Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured
,也许对此有所帮助?
编辑4
所以我将WSGIDaemonProcess更改为
WSGIDaemonProcess myapp python-path=/home/user/projects/myapp python-home=/home/user/projects/app/env/lib/python3.6/site-packages user=<user>
现在我收到这些错误
[Tue Mar 12 10:38:09.111397 2019] [mime_magic:error] [pid 18804] [client ip] AH01512: mod_mime_magic: can't read `/home/user/project/myapp/new/wsgi.py'
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
所以看来我需要卸载mod_wsgi并重新安装才能使用python3.6而不是2.7
我如何成功做到这一点?我卸载了mod_wsgi并尝试使用sudo pip3.6 install mod_wsgi
进行mreinstall现在由于invalid command 'WSGIDaemonProcess'
它无法识别新安装的mod_wsgi并不会启动服务器,这是bc新的下载未配置httpd吗?我该怎么办?
编辑5
成功安装的mod_wsgi已使用正确的python版本编译并能够运行服务器,请将SELinux设置为宽松,以摆脱cant find '/route/to/wsgi/py
。现在我没有出现重复的模块名称“编码”错误。
[Wed Mar 13 15:20:46.133597 2019] [core:notice] [pid 4403] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
[Tue Mar 12 14:11:57.520271 2019] [core:notice] [pid 866] AH00052: child pid 891 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
当前,我的权限全部在用户apache和组apache下,并且似乎都在正确的权限下,我尝试将root用户/组也更改为apache,并在Myapp目录中运行chmod -R 777
确保它具有适当的权限。
项目下的权限:
home/user/projects# ls -l
total 0
drwxrw-r-x. 7 apache apache 109 Mar 12 12:48 myapp
home/user/projects/myapp# ls -l
myapp下的权限:
total 12
drwxrwxr-x. 7 apache apache 4096 Mar 7 13:18 app
drwxr-xr-x. 5 apache apache 56 Mar 12 12:48 env
-rwxrwxr-x. 1 apache apache 535 Mar 5 13:33 manage.py
drwxrwxr-x. 3 apache apache 110 Mar 7 14:27 new
-rw-rw-r--. 1 apache apache 869 Mar 7 14:42 requirements.txt
答案 0 :(得分:2)
根据mod_wsgi的文档:
user =名称|用户=#uid 定义守护程序应以其运行的用户的UNIX用户名或数字用户uid。如果未提供此选项,则守护进程将以与User运行指令所定义的Apache子进程相同的用户身份运行,并且不必自己将其设置为Apache用户。
我想apache用户无法访问您的主目录。尝试将user=myUser
伪指令添加到您的WSGIDaemonProcess,或将目录chown
添加到apache用户。另一种可能的方法是将您的应用程序放入apache用户拥有的目录中。
编辑
我真的应该学习阅读。根据文档,看来您应该使用python3.X解释器重新编译mod_wsgi以便运行python3.X应用程序(对于编译环境和应用程序环境,请使用相同的版本)
如果要使用其他版本的Python,则需要重新安装mod_wsgi,并将其编译为所需的版本。一个mod_wsgi实例不可能同时为Python 2和3运行应用程序。
编辑2
要回答您的评论之一:通常,您不会删除通过pip安装的版本。它无法猜测您是否通过其他软件包管理器AFAIK安装了软件包。我认为您应该将一些 .so(我认为是mod_wsgi [version] .so)复制到pip安装mod_wsgi的目录中(我认为是venv / global site_packages内部)到Apache / Httpd搬出后加载其模块文件(在alpine / ubuntu上类似于/usr/lib/apache2/modules
,所以我猜它是CentOS的/usr/lib/httpd/modules
,但可以不同,对不起,我不能给您更多具体的帮助)此文件夹中的旧mod_wsgi .so。不要忘记先关闭httpd,然后再重新启动。
来源:https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html(第python-home部分)
答案 1 :(得分:2)
尝试在目录级别而不是在文件上进行权限。
<Directory /home/user/projects/myapp/new>
Require all granted
</Directory>
答案 2 :(得分:1)
您可以通过以下方式检查用户和组的apache
egrep -i '^user|^group' /etc/httpd/conf/httpd.conf
因此请确保您拥有/home/user/projects/myapp/new/wsgi.py
通过ls -l
例如,如果用户为apache
且组为apache
,请重试
sudo chown apache:apache /home/user/projects/myapp/new/wsgi.py
答案 3 :(得分:1)
您必须传递环境变量的库位置。
WSGIDaemonProcess myapp python-path=/home/user/projects/myapp python-home=/home/user/projects/myapp/env/lib/<PYTHON VERSION>/site-packages/