我遇到了这个看似最相关的部署选项,因为指南似乎要么引用了mod_wsgi和python2,要么在基于deb的系统上使用了不同的预期路径。
因此,我遵循以下步骤:
#repos for python3.6, wsgi for python3.6
yum install epel-release centos-release-scl
#base packages
yum install python36 python36-devel httpd httpd-devel rh-python36-mod_wsgi
#python3.6 venv
cd /var/www;
python36 -m venv django-venv
source django-venv/bin/activate
pip3 install django
#apache config to support wsgi
edit /etc/httpd/conf/httpd.conf to include
LoadModule wsgi_module modules/mod_wsgi.soapache配置为/var/www/mysite上的django内容提供服务
<VirtualHost *:80>
ServerAdmin foo@mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
WSGIDaemonProcess mysite python-home=/var/www/django-venv/ python-path=/var/www/django-venv/lib/python3.6/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /static /var/www/mysite/static
<Directory /var/www/mysite/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>SEL更改:
chown apache:apache -R /var/www/mysite chown apache:apache -R /var/www/django-venv
httpd成功启动,但我一直在错误日志中获得以下内容:
Current thread 0x00007f5b5a486880 (most recent call first):
[Fri Nov 23 14:29:02.019635 2018] [core:notice] [pid 4837] AH00052: child pid 5159 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'你们能确认一下到目前为止我在这个设置的步骤中遗漏了什么吗?
其他一些信息:
ll /etc/httpd/modules/*wsgi* -rwxr-xr-x. 1 root root 966K Nov 23 09:13 /etc/httpd/modules/mod_wsgi.so
systemctl status -l httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2018-11-23 14:26:16 EET; 13min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 4837 (httpd)
Status: "Total requests: 3; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─4837 /usr/sbin/httpd -DFOREGROUND
├─4839 /usr/sbin/httpd -DFOREGROUND
├─4840 /usr/sbin/httpd -DFOREGROUND
├─4841 /usr/sbin/httpd -DFOREGROUND
├─4842 /usr/sbin/httpd -DFOREGROUND
├─4843 /usr/sbin/httpd -DFOREGROUND
└─4850 /usr/sbin/httpd -DFOREGROUND
Nov 23 14:26:16 www1 systemd[1]: Starting The Apache HTTP Server...
Nov 23 14:26:16 www1 httpd[4837]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::a7a7:b61c:5ffc:b91a. Set the 'ServerName' directive globally to suppress this message
Nov 23 14:26:16 www1 systemd[1]: Started The Apache HTTP Server.发布于 2018-11-27 17:47:35
我有所有事情要做。以下是完整的步骤:
yum install epel-release centos-release-scl
yum install python36 python36-devel httpd httpd-devel rh-python36-mod_wsgi` 检查rh-python36-mod_wsgi是否将所有内容放置在正确的dirs中
rpm -ql rh-python36-mod_wsgi如在下列文件中发现:
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so 将其移至:
/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/etc/httpd/modules/mod_rh-python36-wsgi.so 创建python3 venv。如果您正在从某个地方迁移,而不是在其中创建,请选中SEL以确保apache可以使用它。
cd /var/www
python36 -m venv django-venv
source /var/www/django-venv/activate在/etc/httpd/conf.d/django.conf配置虚拟主机
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
WSGIDaemonProcess mysite python-home=/var/www/django-venv python-path=/var/www/mysite
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /static /var/www/mysite/static
<Directory /var/www/mysite/static>
Require all granted
</Directory>
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>如果项目被移动到/var/www,恢复正确的SEL标签:
restorecon -Rv /var/www使apache拥有的项目dir:
chown -R apache:apache /var/www/mysite如果使用SQLite,允许SEL允许apache访问它(需要改进):
semanage boolean -p http_unified onhttps://serverfault.com/questions/941341
复制相似问题