Mfr*_*man 5 apache django mod-wsgi django-wsgi
版本列表:
Centos 7 --- django 2.1.7 --- Apache 2.4.6 --- Python 3.6
检查EDIT 5以获取最新的错误日志
在此处遵循本教程:https : //www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7
我能够运行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
Run Code Online (Sandbox Code Playgroud)
我希望有人能在我的 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
Run Code Online (Sandbox Code Playgroud)
我不确定这些是否指向所有正确的地方,并希望有人能给我再看一眼。
而且我还没有触及 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()
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)
编辑3
在这个日志文件中,Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5 configured当我运行 python3.6 而不是 2.7.5 时,它说这个,也许改变它会有所帮助?
编辑 4
所以我改变了我的 WSGIDaemonProcess
WSGIDaemonProcess myapp python-path=/home/user/projects/myapp python-home=/home/user/projects/app/env/lib/python3.6/site-packages user=<user>
Run Code Online (Sandbox Code Playgroud)
现在我收到这些错误
[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
Run Code Online (Sandbox Code Playgroud)
所以看起来我需要卸载 mod_wsgi 并重新安装以使用 python3.6 而不是 2.7 进行编译
我怎样才能成功地做到这一点?我卸载 mod_wsgi 并尝试使用 mreinstallsudo pip3.6 install mod_wsgi 现在它无法识别 mod_wsgi 的新安装并且不会启动服务器,因为invalid command 'WSGIDaemonProcess'这是 bc 新下载未配置 httpd?我该怎么做?
编辑 5
成功安装了使用正确 python 版本编译并能够运行服务器的 mod_wsgi,将 SELinux 设置为 permissive 以摆脱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'
Run Code Online (Sandbox Code Playgroud)
目前我的权限都在用户 apache 和组 apache 下,似乎它们都在正确的权限下,我尝试将 root 用户/组也更改为 apache,并chmod -R 777在 Myapp 目录下运行以确保它具有正确的权限。
项目权限:
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
根据 mod_wsgi 的文档:
user=name | user=#uid Defines the UNIX user name or numeric user uid of the user that the daemon processes should be run as. If this option is not supplied the daemon processes will be run as the same user that Apache would run child processes, as defined by the User directive, and it is not necessary to set this to the Apache user yourself.
I suppose that the apache user cannot access your home directory. Either try to add the user=myUserdirective to your WSGIDaemonProcess or chown your directory to the apache user. Another possible way would be to put your application inside a directory owned by apache user.
EDIT
I really should learn to read. According to the docs, it looks like you should recompile mod_wsgi using a python3.X interpreter in order to run python3.X applications (use the same versions for both compiling and application's environment)
If you want to use a different version of Python, you will need to reinstall mod_wsgi, compiling it for the version you want. It is not possible for the one mod_wsgi instance to run applications for both Python 2 and 3 at the same time.
EDIT 2
To answer one of your comments: It's normal that yum won't remove the version you installed through pip. It has no way to guess that you installed packages through other package managers AFAIK. I think that you should copy some the .so (I think it's mod_wsgi[version].so) files that lies in the directory where pip installed mod_wsgi (inside your venv/global site_packages I think) into the folder where Apache/Httpd loads its modules files (it's something like /usr/lib/apache2/modules on alpine/ubuntu so I guess it is /usr/lib/httpd/modules for CentOS, but can be different, sorry I can't give you more specific help) after moving out of this folder the old mod_wsgi.so. Don't forget to shutdown httpd before doing this, and restart it after.
Source: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html (section python-home)
| 归档时间: |
|
| 查看次数: |
2617 次 |
| 最近记录: |