无法使用mod-wsgi在Apache上部署django [英] Cannot deploy django on Apache with mod-wsgi

查看:68
本文介绍了无法使用mod-wsgi在Apache上部署django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在准备将其移至生产服务器的Django应用程序.我已经安装了Apache和mod_wsgi,并使用一个测试来检查它是否可以正常工作.但是现在我在使其与Django一起使用时遇到了问题.

I have been working on a Django app that I am ready to move to the production server. I have Apache and mod_wsgi installed and I used a test to check to see that it all works, and it does. But now I am having problems getting it to work with Django.

我已经创建了wsgi.py文件:

I have created the wsgi.py file:

import os
import os.path
import sys


sys.path.append('/var/www/html/mideastinfo/lib/python2.7/site-packages/django/bin/mideastinfo')
#os.environ['PYTHON_EGG_CACHE'] = 'path to a directory for egg cache'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()

我通过WGSIScriptAlias指向http.conf.它不起作用,我知道它与sys.path有关,我不确定该怎么办.

And I have the http.conf point to it via WGSIScriptAlias. It's not working, I know it has to do with the sys.path, I am not sure what to do.

我有一个开发环境,我在其中进行了所有构建.然后,我将所有项目依赖项安装到服务器用户pip和requirements.txt上.然后,我将项目文件移了过来.但是我认为我弄错了所有的映射和​​路径.有任何想法吗?我觉得距完成此步骤仅一步之遥.

I had a development environment in which I did all the build. Then, I installed all the project dependencies onto the server user pip and a requirements.txt. Then, I moved my project files over. But I think I am getting all the mapping and pathing wrong. Any ideas? I feel like I am one step away from being done with this.

推荐答案

我将分享配置简单示例的方式:

I will share how I've configured a simple example:

import os,sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('PATH TO YOUR PROJECT ROOT')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

在Apache配置上的VirtualHost指令上,您必须具有:

On your VirtualHost directive on Apache config you must have:

WSGIScriptAlias / /PATH/TO/YOUR/.wsgi

示例:

<VirtualHost *:80>
    ErrorLog /home/user/logs/error.log
    ...
    WSGIScriptAlias / /PATH/TO/YOUR/.wsgi
    ...
</VirtualHost>

这篇关于无法使用mod-wsgi在Apache上部署django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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