繁体   English   中英

httpd 与 django3 与 python3.6 在 Centos7

[英]httpd with django3 with python3.6 on Centos7

我们正在尝试使用 httpd 运行 django3(Centos7 上的 python3.6)。

当我通过 HTTPD 运行它时出现以下错误。

[Tue Jan 12 06:52:04.575618 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] Traceback (most recent call last):
[Tue Jan 12 06:52:04.575665 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/srv/django/django/wsgi.py", line 16, in <module>
[Tue Jan 12 06:52:04.575670 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     application=get_wsgi_application()
[Tue Jan 12 06:52:04.575678 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jan 12 06:52:04.575682 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     django.setup(set_prefix=False)
[Tue Jan 12 06:52:04.575690 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[Tue Jan 12 06:52:04.575694 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Jan 12 06:52:04.575701 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Tue Jan 12 06:52:04.575706 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     self._setup(name)
[Tue Jan 12 06:52:04.575713 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
[Tue Jan 12 06:52:04.575717 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     self._wrapped = Settings(settings_module)
[Tue Jan 12 06:52:04.575724 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
[Tue Jan 12 06:52:04.575729 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Jan 12 06:52:04.575736 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[Tue Jan 12 06:52:04.575740 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]     return _bootstrap._gcd_import(name[level:], package, level)
[Tue Jan 12 06:52:04.575747 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Jan 12 06:52:04.575755 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Jan 12 06:52:04.575762 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Tue Jan 12 06:52:04.575780 2021] [wsgi:error] [pid 16778] [remote 100.10.100.10:53489] ModuleNotFoundError: No module named 'django.settings'```

我在 /etc/httpd/conf.d 中的 django.conf 文件如下:

Alias /static /srv/static
<Directory /srv/static>
Require all granted
</Directory>

<Directory /srv/django/django>
   <Files wsgi.py>
       Require all granted
   </Files>
</Directory>

WSGIDaemonProcess django python-path=/srv/django:/usr/local/lib/python3.6/site-packages
WSGIProcessGroup django
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /srv/django/django/wsgi.py

和我的 wsgi.py 如下:

import os
import sys
from django.core.wsgi import get_wsgi_application
os.chdir('/srv/django/')
sys.path.append('/srv/django/')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django.settings')
application=get_wsgi_application()

我们安装了以下软件包

python3-devel.x86_64 
rh-python36-mod_wsgi.x86_64
yum install httpd-devel

django 项目本身工作正常

100.10.100.10 (/srv/django/)-1003> python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
January 12, 2021 - 05:22:31
Django version 3.1.5, using settings 'django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

我错过了什么?

我不太熟悉 Apache Httpd 与 WSGI 的工作情况,但是如果您单独启动 Django 并且您只是想快速运行反向代理,您可以执行以下操作:

<VirtualHost *:80>
    ServerAdmin admin@localhost
    ProxyRequests off
    DocumentRoot /var/www
    # SSLProxyEngine on
    # ProxyPreserveHost On

    ServerName www.yoursite.net

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel error

    <Location />
        ProxyPass http://www.yourwebsite.net/
        ProxyPassReverse http://localhost:8080/
        Order allow,deny
        Allow from all
    </Location>

</VirtualHost>

就错误而言,看起来 wsgi.py 找不到django.settings意味着django目录和settings模块不在当前路径中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM