首页 \ 问答 \ apache mod_wsgi错误与django在virtualenv中(apache mod_wsgi error with django in virtualenv)

apache mod_wsgi错误与django在virtualenv中(apache mod_wsgi error with django in virtualenv)

我似乎无法找到一个好的答案。 在将其作为WSGIDaemon运行时,谁需要拥有virtualenv? 我假设我的操作系统(Ubuntu 16)www-data,但我想确定。 根据这篇文章的答案,尝试一些新的东西让这件事工作......

django apache配置与WSGIDaemonProcess无法正常工作

django项目,virtualenv文件夹或两者都需要由apache组拥有吗? 在没有指定端口的情况下,需要为django项目提供什么样的所有权? 为什么我会得到以下内容?

根本问题:

 Call to 'site.addsitedir()' failed for '(null)'

当我启动Apache时,我收到此错误。 我遵循了几个不同的指南,包括: http//modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.htmlhttps://docs.djangoproject.com/en/1.10/howto/部署/ wsgi / modwsgi /但没有成功。

我的虚拟环境路径是/usr/local/virtualenvs/servicesite

我的django项目路径是/home/addohm/projects/rtservice/servicesite 这是manage.py所在的位置 ,它将/home/addohm/projects/rtservice/servicesite/servicesite留作我的wsgi.py的位置。

wsgi.py:

SERVICESITE = ['/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages']

import os
import sys
import site

prev_sys_path = list(sys.path)

for directory in SERVICESITE
        site.addsitedir(directory)

new_sys_path = []
for item in list(sys.path):
        if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
sys.path[:0] = new_sys_path

"""  **Doesn't seem to work, throwing error in apache logs**
site.addsitedir('/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages')
"""

from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "servicesite.settings")
application = get_wsgi_application()
DJANGO_PATH =  os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)

apache2.conf

[...]

WSGIDaemonProcess servicesite python-path=/home/addohm/projects/rtservice/servicesite:/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages
WSGIProcessGroup servicesite
WSGIScriptAlias / /home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py

Alias /static/ /home/addohm/projects/rtservice/servicesite/static/
<Directory /home/addohm/projects/rtservice/servicesite/static/>
        Require all granted
</Directory>

<Directory /home/addohm/projects/rtservice/servicesite/servicesite>
        <Files wsgy.py>
                Require all granted
        </Files>
</Directory>

[...]


I can't seem to find a good answer to this. Who needs to own the virtualenv when running it as a WSGIDaemon? I assume on my OS (Ubuntu 16) www-data, but I want to be sure. Trying some new things to get this thing working based off of the answer from this post...

django apache configuration with WSGIDaemonProcess not working

Does the django project, the virtualenv folder, or both need to be owned by the apache group? What ownerships need to be in place to serve a django project without specifying a port? Why do I get the following?

The root problem:

 Call to 'site.addsitedir()' failed for '(null)'

When I start apache, I get this error. I've followed several different guides, including: http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html and https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/ but have had zero success.

My virtual environment path is /usr/local/virtualenvs/servicesite

My django project path is /home/addohm/projects/rtservice/servicesite this is where manage.py resides, which leaves /home/addohm/projects/rtservice/servicesite/servicesite as the location of my wsgi.py.

wsgi.py:

SERVICESITE = ['/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages']

import os
import sys
import site

prev_sys_path = list(sys.path)

for directory in SERVICESITE
        site.addsitedir(directory)

new_sys_path = []
for item in list(sys.path):
        if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
sys.path[:0] = new_sys_path

"""  **Doesn't seem to work, throwing error in apache logs**
site.addsitedir('/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages')
"""

from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "servicesite.settings")
application = get_wsgi_application()
DJANGO_PATH =  os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)

apache2.conf

[...]

WSGIDaemonProcess servicesite python-path=/home/addohm/projects/rtservice/servicesite:/usr/local/virtualenvs/servicesite/lib/python3.5/site-packages
WSGIProcessGroup servicesite
WSGIScriptAlias / /home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py

Alias /static/ /home/addohm/projects/rtservice/servicesite/static/
<Directory /home/addohm/projects/rtservice/servicesite/static/>
        Require all granted
</Directory>

<Directory /home/addohm/projects/rtservice/servicesite/servicesite>
        <Files wsgy.py>
                Require all granted
        </Files>
</Directory>

[...]


原文:https://stackoverflow.com/questions/39948367
更新时间:2023-02-03 17:02

最满意答案

自己想出来: 什么是Hi / Lo算法?


Figured it out myself: What's the Hi/Lo algorithm?

相关问答

更多
  • insert语句后加个returning就行了 insert into .... returning ID; returning后的格式类似于select的, 返回值格式也类似于select ID from ...
  • insert into PRODUCT (你建的序列.NEXTVAL,PRD_DESCRIPTION) values (id,description) 在每次插入数据的时候,id都会按你建的序列的增量自动增加。 sequence就是所谓的序列号,每次取的时候它会自动增加,一般用在需要按序列号排序的地方。 1、 create sequence 你首先要有create sequence或者create any sequence权限, create sequence emp_sequence INCREMENT ...
  • 它用于调用FBSDKLoginButton的initialize方法。 +(void)initialize是在初始化类的任何实例之前调用的方法。 它只召唤一次。 [FBSDKLoginButton class]用于触发要调用的initialize方法。 It is used to call the initialize method of the FBSDKLoginButton. The +(void)initialize is a method that is called before any ins ...
  • 当ListIterator对象中的迭代按指数正确的顺序返回时,与i1,i2是独立的: import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class Main { public static void main(String[] args) { List list = new ArrayList(); ...
  • 我想你会在这里找到你的答案 使用列的标识属性,您可以轻松生成自动递增数字(通常用作主键)。 使用Sequence,它将是一个不同的对象,您可以在插入时附加到表列。 与身份不同,列值的下一个数字将从内存而不是从磁盘检索,这使得Sequence显着快于Identity。 我们将在下面的例子中看到这一点。 在这里 : 序列:SQL Server社区多年来已经请求了序列,并且包含在此版本中。 Sequence是用户定义的对象,用于生成一个数字序列。 以下是使用Sequence的示例。 在这里也是: SQL Serv ...
  • LSTM是循环神经网络的一个子类。 递归神经网络被定义应用于连续数据,其不失一般性意味着随时间变化的数据样本。 然后通过有限时间窗口上的样本值来描述数据样本的完整历史记录,也就是说,如果您的数据存在于N维空间并随着时间步长演化,则您的输入表示必须是形状的(num_samples,t ,N)。 您的数据不符合上述说明。 然而,我认为这个表示意味着你有一个标量值x,它在7个时间点上演化,这样x [0] = 1.23,x [1] = 2.24等。 如果是这样的话,你需要重新塑形你的输入,而不是一个7个元素的列表, ...
  • SecurityBits="11"表示Users can read and edit all items. Sequence="110"表示110 is the ordering priority to use for the list template on the Create page 阅读文档了解更多信息 SecurityBits="11" means Users can read and edit all items. Sequence="110" means 110 is the orderin ...
  • 自己想出来: 什么是Hi / Lo算法? Figured it out myself: What's the Hi/Lo algorithm?
  • 在C中,“字符串”被定义为以空字符结尾的char的数组(可能是较大数组的子数组)。 多字节字符串函数对字符串进行操作,处理多字节字符,直到它们到达字符串的末尾(或目标缓冲区中的空间不足)。 对字节“序列”( char s)进行操作的多字节字符函数一次只转换一个多字节字符(或者,在mbrtowc的情况下,可能甚至更少)。 不要求输入char数组是字符串。 In C, a "string" is defined as an array (possibly a subarray of a larger array ...
  • 您可以通过传递数组和start参数来完成此操作: private static boolean arrPattern(int[] arr) { return arrPattern(int[] arr, 0); } private static boolean arrPattern(int[] arr, int startpos) { ... } 在递归调用中传递startpos + 1 ,然后检查startpos是否在最后。 You can do this by passing an a ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。