启动缺少mod\u wsgi的apachedango.core.wsgi文件

2024-04-23 16:56:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习django,并尝试在apache下部署我的第一个基本django。你知道吗

到目前为止我所做的: 根目录下:

installed python3.4
pip3.4 install virtualenvwrapper

在用户“Cheng”下:

added to .bashrc:
    VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.4
    source /usr/local/bin/virtualenvwrapper.sh
mkvirtulenv ifthq

根下

pip3.4 install django

在“(ifthq)cheng”下

navigate to /var/www
django-admin.py startproject ifthq
cd ifthq
python manage.py runserver  <--works no problem

然后是有趣的部分,将项目附加到apache:

在根下,我设置ifthq.conf文件在/etc/httpd/的conf.d目录中。内部ifthq.conf文件是:

WSGIPythonPath /var/www/ifthq:/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages/

<VirtualHost *:80>
    ServerName www.ifthq.com
    ServerAlias ifthq.com
    ServerAdmin cheng@trekfederation.com

        <Directory />
         Options FollowSymLinks
         AllowOverride None
        </Directory>

         # Alias /robots.txt /www/STORE/coffestatic/robots.txt
         # Alias /favicon.ico /www/STORE/coffeestatic/favicon.ico

         Alias /static/ /var/www/ifthq/static/


        <Directory /var/www/ifthq/>
         Order allow,deny
         Allow from all
        </Directory>

    WSGIScriptAlias / /var/www/ifthq/ifthq/wsgi.py

    ErrorLog /var/log/httpd/error.log

    LogLevel warn

    CustomLog /var/log/httpd/access.log combined
</VirtualHost>

当我启动apache时,会得到臭名昭著的500(内部服务器错误)。经进一步审查,我得到了以下答复:错误.log地址:

[Sun Oct 18 18:34:55.944407 2015] [:error] [pid 19250] [client 144.76.29.66:56465] ImportError: No module named django.core.wsgi

如您所见,我正试图让apache为页面提供服务。这个wgsi.py公司位置正确。站点包位置正确。我觉得我错过了一些愚蠢的事情。在root-outside-virtualenv中,我做了一个pip3.4 install django但没有用。你知道吗

我还缺什么? 谢谢

更新1 这是我的wsgi.py公司已更新,仍不可用:

"""
WSGI config for ifthq project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/var/www/ifthq')

# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages')

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ifthq.settings")

application = get_wsgi_application()

Tags: thepathdjangopycomlogwsgiapplication
2条回答

我找到了答案。 使用另一个stackoverflow,我正在尝试再次重新定位它….我发现我的mod\u wsgi是在默认python下安装的,当时安装在YUM下。你知道吗

我就是这么做的: 我从源代码下载了新的modèwsgi,提取它,然后进入文件夹。然后我运行以下命令:

sudo ./configure  with-python=/usr/local/bin/python3.4
sudo make
sudo make install

这会将modèwsgi重置为正确的python,然后一切都会就绪。你知道吗

你试过这个了吗?ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI我想这是你的问题wsgi.py公司代码。你知道吗

编辑:

我可以向您展示在Centos VPS中为我工作的配置:

在httpd.conf文件你知道吗

WSGIPythonPath /path/to/project/folder
<VirtualHost YourServerIp:80>
     #WSGI conf

     ServerName mysite.co
     ServerAlias www.mysite.co
     WSGIScriptAlias / /path/to/your/project/main/wsgi.py

     Alias /robots.txt /path/to/your/robots.txt/folder

     Alias /media/ /path/to/your/project/media/folder/
     Alias /static/ /path/to/your/project/static/folder/

     <Directory /path/to/your/project/static/folder/>
     Order deny,allow
     Allow from all
     </Directory>

     <Directory /path/to/your/project/media/folder/>
     Order deny,allow
     Allow from all
     </Directory>

     <Directory /path/to/your/project/wsgi.py/folder/>
     <Files wsgi.py>
     Order deny,allow
     Allow from all
     </Files>
     </Directory>
</VirtualHost>

在我的心里wsgi.py公司你知道吗

 """
WSGI config for project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainFolder.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

相关问题 更多 >