启用S​​SL时,Django模块的ImportError(嵌套管理和嵌套内联)

时间:2015-11-23 10:49:33

标签: python django ssl django-admin

我在启用SSL的生产环境中遇到以下错误。

ssl_error_log:

[Wed Nov 18 11:14:16.303520 2015] [:error] [pid 14069] [remote 128.132.66.000:116] mod_wsgi (pid=14069): Target WSGI script '/apps/staging/wisdmepid/django_version/django_version/wsgi.py' cannot be loaded as Python module.[Wed Nov 18 11:14:16.303584 2015] [:error] [pid 14069] [remote 128.132.66.000:116] mod_wsgi (pid=14069): Exception occurred processing WSGI script '/apps/staging/wisdmepid/django_version/django_version/wsgi.py'.
[Wed Nov 18 11:14:16.303617 2015] [:error] [pid 14069] [remote 128.132.66.000:116] Traceback (most recent call last):
[Wed Nov 18 11:14:16.303641 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/apps/staging/wisdmepid/django_version/django_version/wsgi.py", line 18, in <module>
[Wed Nov 18 11:14:16.303732 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     application = get_wsgi_application()[Wed Nov 18 11:14:16.303747 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Nov 18 11:14:16.303805 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     django.setup()
[Wed Nov 18 11:14:16.303816 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Wed Nov 18 11:14:16.303861 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     apps.populate(settings.INSTALLED_APPS)
[Wed Nov 18 11:14:16.303870 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
[Wed Nov 18 11:14:16.304015 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     app_config = AppConfig.create(entry)
[Wed Nov 18 11:14:16.304031 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/apps/config.py", line 86, in create[Wed Nov 18 11:14:16.304125 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     module = import_module(entry)
[Wed Nov 18 11:14:16.304136 2015] [:error] [pid 14069] [remote 128.132.66.000:116]   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Wed Nov 18 11:14:16.304199 2015] [:error] [pid 14069] [remote 128.132.66.000:116]     __import__(name)
[Wed Nov 18 11:14:16.304225 2015] [:error] [pid 14069] [remote 128.132.66.000:116] ImportError: No module named nested_admin[Wed Nov 18 11:14:29.322753 2015] [:error] [pid 14068] [remote 128.132.66.000:104] mod_wsgi (pid=14068): Target WSGI script '/apps/staging/wisdmepid/django_version/django_version/wsgi.py' cannot be loaded as Python module.[Wed Nov 18 11:14:29.322819 2015] [:error] [pid 14068] [remote 128.132.66.000:104] mod_wsgi (pid=14068): Exception occurred processing WSGI script '/apps/staging/wisdmepid/django_version/django_version/wsgi.py'.[Wed Nov 18 11:14:29.322851 2015] [:error] [pid 14068] [remote 128.132.66.000:104] Traceback (most recent call last):
[Wed Nov 18 11:14:29.322873 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/apps/staging/wisdmepid/django_version/django_version/wsgi.py", line 18, in <module>
[Wed Nov 18 11:14:29.322955 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     application = get_wsgi_application()[Wed Nov 18 11:14:29.322970 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Nov 18 11:14:29.323024 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     django.setup()
[Wed Nov 18 11:14:29.323034 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Wed Nov 18 11:14:29.323096 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     apps.populate(settings.INSTALLED_APPS)[Wed Nov 18 11:14:29.323107 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
[Wed Nov 18 11:14:29.323251 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     app_config = AppConfig.create(entry)
[Wed Nov 18 11:14:29.323266 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/apps/staging/wisdmepid/django_version/env/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
[Wed Nov 18 11:14:29.323374 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     module = import_module(entry)[Wed Nov 18 11:14:29.323393 2015] [:error] [pid 14068] [remote 128.132.66.000:104]   File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Wed Nov 18 11:14:29.323448 2015] [:error] [pid 14068] [remote 128.132.66.000:104]     __import__(name)
[Wed Nov 18 11:14:29.323471 2015] [:error] [pid 14068] [remote 128.132.66.000:104] ImportError: No module named nested_admin

我已经安装了模块django-nested-admin。当我使用django-nested-inline而不是django-nested-admin时,我也会遇到同样的错误。知道什么是错的吗?

在我得到的网站上:

  

内部服务器错误

     

服务器遇到内部错误或配置错误   无法完成您的请求。

     

请与root @ localhost的服务器管理员联系以告知   它们发生此错误的时间以及您执行的操作   就在这个错误之前。

     

有关此错误的详细信息可能在服务器错误中可用   日志中。

该代码在我们的非SSL站点中完美运行 我已经尝试了thisthis中提到的解决方案。没工作。任何指针都非常有用。感谢。

这是我们的apache配置文件。这不是实际的,但原始配置与此一致。

<VirtualHost *:80>
    ServerName bogus.example.com:80
    ErrorLog logs/error_log
    TransferLog logs/access_log
    LogLevel warn

    RewriteEngine On
    RewriteRule ^/?sslsite/(.*) https://%{SERVER_NAME}/sslsite/$1 [R,L]


        alias /static/notsslsite /apps/deployment/notsslsite/django_version/static
    <Directory /apps/deployment/notsslsite/django_version/static>
        Require all granted
    </Directory>

    <Directory /apps/deployment/notsslsite/django_version/django_version>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess notsslsite processes=2 python-path=/apps/deployment/notsslsite/django_version:/apps/deployment/notsslsite/django_version/env/lib/python2.7/site-packages
        WSGIProcessGroup notsslsite
        WSGIScriptAlias /notsslsite /apps/deployment/notsslsite/django_version/django_version/wsgi.py process-group=notsslsite

</VirtualHost>

<VirtualHost *:443>
    ServerName bogus.example.com:443
    ErrorLog logs/ssl_error_log
    TransferLog logs/ssl_access_log
    LogLevel warn
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateFile /etc/httpd/ssl/bogus.example.com.crt
    SSLCertificateKeyFile /etc/httpd/ssl/bogus.example.com.key
    SSLCertificateChainFile /etc/httpd/ssl/bogus_chain.pem


    SetEnvIf User-Agent ".*MSIE.*" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
    CustomLog logs/ssl_request_log \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        alias /static/sslsite /apps/staging/sslsite/django_version/static
    <Directory /apps/staging/sslsite/django_version/static>
        Require all granted
    </Directory>

    <Directory /apps/staging/sslsite/django_version/django_version>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess sslsite processes=2 python-path=/apps/staging/sslsite/django_version:/apps/staging/sslsite/django_version/env/lib/python2.7/site-packages
        WSGIProcessGroup sslsite
        WSGIScriptAlias /sslsite /apps/staging/sslsite/django_version/django_version/wsgi.py process-group=sslsite

</VirtualHost>

1 个答案:

答案 0 :(得分:0)

这是来自非ssl配置的WSGIDaemonProcess设置

WSGIDaemonProcess notsslsite processes=2 python-path=/apps/deployment/notsslsite/django_version:/apps/deployment/notsslsite/django_version/env/lib/python2.7/site-packages

这是来自ssl配置

WSGIDaemonProcess sslsite processes=2 python-path=/apps/staging/sslsite/django_version:/apps/staging/sslsite/django_version/env/lib/python2.7/site-packages

您正在为ssl和非ssl实例使用不同的python路径,并且可能nested_admin未安装在第二个实例中。这只是你的apache设置中django的重要区别。尝试在ssl站点上设置与非ssl相同的环境,并检查它是否可行。如果可以,请从ssl config在环境中安装正确的软件包。如果它不能工作,可能是你的虚拟环境坏了,试着重新创建它。