错误,同时通过上传的mod_wsgi Django项目到Apache服务器 [英] Error while uploading Django project to a Apache server via mod_wsgi

查看:115
本文介绍了错误,同时通过上传的mod_wsgi Django项目到Apache服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DigitalOcean和no-ip.com创建一个液滴(云服务器),我给它的主机名 - project.ddns.net.By SSH(ING)为我安装PIP液滴和的virtualenv

I created a droplet(cloud server) on DigitalOcean and with no-ip.com I gave it the hostname - project.ddns.net.By ssh(ing) into the droplet I installed pip and virtualenv.

里面的/ var / WWW /我创建了一个的virtualenv从我project.The目录PPC结构的GitHub克隆储备库 -

Inside /var/www/ I created a virtualenv and cloned the repository from github of my project.The directory struture is -

project_revamped  (root of the project)
->requirements
  ->base.txt
  ->dev.txt
->project (django project)
   ->static
   ->media
   ->apps (folder which contains apps)
   ->manage.py
   ->project
      ->urls.py
      ->settings
          ->base.py
          ->dev.py  

遵循我创建在/ etc / Apache2的httpd.conf文件的路径和apache2.conf包括它。官方的Django文档

By following the official Django documentation I created httpd.conf in the /etc/apache2 path and included it in apache2.conf.

我httpd.confs内容本 -

My httpd.confs reads as this -

WSGIScriptAlias / /var/www/project_revamped/project/project/wsgi.py
WSGIPythonPath     /var/www/project_revamped/project:/var/www/.virtualenvs/projectenv/local/l    ib/python2.7/site-packages
<Directory /var/www/project_revamped/project/project>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

和我wsgi.py内容本 -

and my wsgi.py reads as this -

import os
import sys

#Add the app's directory to the python path
sys.path.append('/var/www/project_revamped/project')
sys.path.append('/var/www/project_revamped/project/project')

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings.dev'

#Activate your virtualenv
activate_env =     os.path.expanduser('/var/www/.virtualenvs/typesetenv/bin/activate_this.py')
execfile(activate_env, dict(__file__=activate_env))

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

改变我终于放弃了命令文件后 -
    服务的Apache2重装
    服务的Apache2重启

After changing the files I finally gave the commands - service apache2 reload service apache2 restart

不过做这些事情之后对应的IP说,有一些问题,服务器并发送500 error.I想这个问题是某处在我的配置,因为Apache服务器是在回应工作fine.After包括我的Django项目它存在的问题开始。

However after doing these things right the corresponding ip says there is some problem the server and sends 500 error.I guess the problem is somewhere in my configuration because apache server was responding working fine.After I include django project with it the problem starts.

检查错误日志后,我发现这些错误信息 -

After checking the error logs I found these error messages -

mod_wsgi (pid=29458): Target WSGI script '/var/www/project_revamped/project/project/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=29458): Exception occurred processing WSGI script '/var/www/project_revamped/project/project/wsgi.py'.
 File "/var/www/project_revamped/project/project/wsgi.py", line 28, in     <module>
[:error] [pid 29458:tid 140073924572928] [client 103.16.70.147:33613]     application = get_wsgi_application()

任何人可以请帮我在这里的配置?我被困在这过去的2天,在互联网上每一个不同的文章讲述了不同的故事。

Can anybody please help me here in the configuration? I am stuck in this for past 2 days and every different article on the internet tells the different story.

推荐答案

您可以看看为Apache我的虚拟主机配置与mod_wsgi的。这个模板可以项目创建过程中被自动填写,但您可以填写/替换变量,并剥夺它归结为你的需要:

You may have a look at my VirtualHost configuration for Apache with mod_wsgi. This template can be automatically filled during project-creation, but you may be able to fill/replace variables and strip it down to your needs:

<VirtualHost *:80>
    # This is name based virtual hosting. So place an appropriate server name
    #   here. Example: django.devsrv.local
    ServerName  [[SERVER_NAME]]
    ServerAdmin webmaster@localhost

    # This alias makes serving static files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /static/  {{ project_directory }}/run/static/

    # This alias makes serving media files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /media/  {{ project_directory }}/run/media/

    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   {{ project_directory }}/{{ project_name }}/wsgi.py

    # PROCESS_NAME specifies a distinct name of this process
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
    # PATH/TO/PROJECT_ROOT is the full path to your project's root directory, 
    #   containing your project files
    # PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full
    #   path to its directory.
    #   Generally you must specify the path to Python's site-packages.
    WSGIDaemonProcess   {{ project_name }}  python-path={{ project_directory }}:{{ project_directory }}/../lib/python2.7/site-packages

    # PROCESS_GROUP specifies a distinct name for the process group
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup
    WSGIProcessGroup    {{ project_name }}

    # Serving static files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory {{ project_directory }}/run/static>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    # Serving media files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory {{ project_directory }}/run/media>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    # PROJECT_NAME is used to seperate the log files of this application
    ErrorLog    ${APACHE_LOG_DIR}/{{ project_name }}_error.log
    CustomLog   ${APACHE_LOG_DIR}/{{ project_name }}_access.log combined
</VirtualHost>

您可能会看到 GitHub上并的此处是RTD.org Apache2的-conf的的文档

You may see my project-skeleton on GitHub and here is the documentation of the Apache2-conf on RTD.org

这篇关于错误,同时通过上传的mod_wsgi Django项目到Apache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆