想了解使用mod_wsgi安装Django的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于wemod安装的相关问题,此外,我们还将为您介绍关于ApacheDjangoMod_Wsgi–自动重
想了解使用mod_wsgi安装Django的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于wemod安装的相关问题,此外,我们还将为您介绍关于Apache Django Mod_Wsgi – 自动重载、apache+mod_wsgi+django 的环境配置、apache+mod_wsgi+django 配置、apache和mod_wsgi的多个django网站的新知识。
本文目录一览:- 使用mod_wsgi安装Django(wemod安装)
- Apache Django Mod_Wsgi – 自动重载
- apache+mod_wsgi+django 的环境配置
- apache+mod_wsgi+django 配置
- apache和mod_wsgi的多个django网站
使用mod_wsgi安装Django(wemod安装)
我使用Django
1.0编写了一个应用程序。django测试服务器可以正常工作。但是,当我尝试将其放入更可能的生产环境中时,Apache服务器无法运行该应用程序。我使用的服务器是WAMP2.0。我多年来一直是PHP程序员,并且很久以前就一直在使用WAMPServer。我安装了mod_wsgi.so,看起来工作正常(没有服务错误),但是我无法配置httpd.conf来查看位于服务器根目录之外的python脚本。
就目前而言,我很乐于覆盖文档根目录,而是从文档根目录提供django应用程序,因此httpd.conf行应如下所示:
WSGIScriptAlias / C:/用户/Marcos/Documents/mysite/apache/django.wsgi
但服务器的响应是403禁止访问
答案1
小编典典你有:
WSGIScriptAlias / /C:/Users/Marcos/Documents/mysite/apache/django.wsgi
这是错误的,因为RHS不是有效的Windows路径名。采用:
WSGIScriptAlias / C:/Users/Marcos/Documents/mysite/apache/django.wsgi
也就是说,Windows驱动器说明符前没有斜杠。
除此之外,请遵循其他人指出的mod_wsgi文档。
海报编辑的问题可以更改帖子中现在出现的错字,而不是他的配置有问题。
在这种情况下,导致403的下一个原因如下。
首先是您还需要具备:
<Directory C:/Users/Marcos/Documents/mysite/apache>Order deny,allowAllow from all</Directory>
如果您没有该权限,则不会授予Apache从该目录提供脚本服务的权限,因此将返回FORBIDDEN(403)。
其次,您确实拥有该文件,但是不承认您这样做,并且该目录或WSGI脚本文件对于Windows服务在Windows下运行的用户不可读。
Apache Django Mod_Wsgi – 自动重载
我试图自动重新加载我的本地Windows机器上使用Apache + mod_wsgi的Django应用程序。
我想知道我在哪里添加下面的文章中引用的代码:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Change detected to ''%s''.'' % (prefix,path) print >> sys.stderr,''%s Triggering Apache restart.'' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1)
如何在Apacheasynchronous客户端中configuration允许的挂起请求数量
无法导入/没有名为与Django错误的模块
node.js与Apache PHP一起运行?
如何htaccessredirect这个长的url?
multipartentity不能被parsing为一个types
Windows生产服务器上的Drupal 7和wordpress 3.8?
404未find在此服务器上未find请求的URL
没有findAndroid库
www将301redirect到使用httpd.conf的非www的语法
我试图在Windows 7 x64上构buildApache Hadoop 2.5.0,但是我仍然遇到未知的错误
读:
http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html
它告诉你在使用Django的时候文件的放置位置。 您只需要在与Windows相关的源代码重新加载文档部分中更改每个人都指出的代码。 另请阅读:
http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-on.html
这解释了与Windows相关的第一个变体。
您替换同一篇文章中上面的代码块中提到的重新启动函数。
您可以在您在页面上找到的以下代码块中替换重新启动功能:
Monitoring For Code Changes The use of signals to restart a daemon process Could also be employed in a mechanism which automatically detects changes to any Python modules or dependent files. This Could be achieved by creating a thread at startup which periodically looks to see if file timestamps have changed and trigger a restart if they have. Example code for such an automatic restart mechanism which is compatible with how mod_wsgi works is shown below. import os import sys import time import signal import threading import atexit import Queue _interval = 1.0 _times = {} _files = [] _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Triggering process restart.'' % prefix os.kill(os.getpid(),signal.SIGINT)
我在我的服务器上使用这个代码
touch site.wsgi
它的工作。 在浏览器重新加载页面后,我得到页面的变化。 可能是丑陋 – 但简单,没有必要重新启动Apache。
我使用Bitnami DjangoStack http://bitnami.org/stack/djangostack和安装在D: BitNami DjangoStack和C: Documents and Settings tsurahman BitNami DjangoStack projects myproject上的Windows XP作为项目目录(默认安装)
如在http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Apache_Processes中 ,我添加
MaxRequestsPerChild 1
在文件D: BitNami DjangoStack apps django conf django.conf中查看Graham Dumpleton的评论
然后我使用http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes中的内容在我的项目目录中创建了一个文件monitor.py ,并用http://code.google.com替换_restart方法/ p / modwsgi / wiki / ReloadingSourceCode#Restarting_Windows_Apache ,这里是脚本的一部分
.... _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Triggering Apache restart.'' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1) def _modified(path): try: ....
并在文件D: BitNami DjangoStack apps django scripts django.wsgi中 ,
.... import django.core.handlers.wsgi import monitor monitor.start(interval=1.0) monitor.track(os.path.join(os.path.dirname(__file__),''site.cf'')) application = django.core.handlers.wsgi.WsgiHandler()
然后重新启动Apache服务器
总结
以上是小编为你收集整理的Apache Django Mod_Wsgi – 自动重载全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
apache+mod_wsgi+django 的环境配置
在原先使用 django 开发完成项目的时候需要部署到服务器上面所以选择了 apache 和 mod_wsgi 的搭配,这些项目在网上有很多发行的二进制版本,当时没有怎么考虑就直接从网上下载版本下来,全部同一种 vc 编译器的版本的 64 位程序,配置好后整个项目可以运行起来后,之后就发现了每次停止服务的时候就会非常卡顿,多次重启服务后,apache 进程还会多了几个,在询问了 mod_wsgi 的作者之后才了解了问题。
首先是选择 django 的版本,一般来说是选择比较新的版本,之后是 python 的版本,这里 python 的版本有 2.7 和 3.6 的这两种版本,之前是选择 2.7 的版本,django 本身也是有支持 3.6 的版本,所以建议都选择 3.0 以上的版本,这个会是以后的主流。接下来就是 apache 的版本,选择 2.4 的版本,在这里 apache 官网上面是没有提供二进制的发行版本。网络上有很多发行版本,比如 ApacheLounge,ApacheHaus。在这里如果是使用 mod_wsgi 这个模块就一定要选择 ApacheLounge 网站上面的 apache 发行的二进制版本,其它发行的版本没有办法编译 mod_wsgi。mod_wsgi 到 github 上面下载源码直接安装到自己的 python 里面。mod_wsgi 也可以编译成 so 文件复制到 apache 里面作为一个模块,这两种方式没有什么差别。
介绍一些基本的软件。
python:https://www.python.org/downloads/windows/
apache:http://www.apachelounge.com/
django:https://www.djangoproject.com/
mod_wsgi:https://github.com/GrahamDumpleton/mod_wsgi
mod_wsgi doc:http://modwsgi.readthedocs.io/en/develop/index.html
以上的 vc 版本要全部是要一致,比如全是 vs2012 的,32 位或者 64 位的。自己的电脑上面需要安装微软的编译器不然无法安装 mod_wsgi 和其它的第三方库。
mod_wsgi 的使用在 github 的官网上面有详细的说明,这里介绍的是编译成 so 文件和安装到 python 里面,编译成 so 文件的话,电脑上面有微软的编译器,然后在源码目录里面有 win 文件夹,这里面的文件选择对应的环境修改里面的内容,执行命令就可以编译成功了,这种方式作者已经不推荐了。安装到 python 里面比较简单。如果是下载了源码的话执行:pip setup.py install,如果是使用 pip 安装的话:pip install mod_wsgi,这里有个前提条件就是 c 盘里面有 apache 二进制的文件夹名字就是 Apache24 或者 Apache22,或者是设置环境变量 MOD_WSGI_APACHE_ROOTDIR 设置 apache 的路径,具体的参考说明:
https://github.com/GrahamDumpleton/mod_wsgi/issues/188
python 里面安装完了 mod_wsgi 或者是个 so 文件,就需要配置 apache 的配置文件,添加一下信息
LoadModule wsgi_module modules/mod_wsgi-py27.so (这个是模块的路径,windows 下是 pyd)
WSGIPythonHome /usr/local/lib (python 的安装目录或者是虚拟环境)
<Directory /usr/local/wsgi/scripts>
Order allow,deny
Allow from all
</Directory> (设置脚本目录可以访问)
WSGIScriptAlias /myapp/usr/local/wsgi/scripts/myapp.wsgi (这个命令是设置访问的地址和执行的脚本,在下载的 mod_wsgi 的源码里面有一些模板)
在命令行下面可以使用 mod_wsgi-express 来获取配置信息,windows 下没有启动服务这样的命令,
之后启动一个 apache 就可以了运行起来了,可以看到一些效果。
像这种的环境配置个人觉得比较的繁琐不是很简单,要是简单的话就好了。最后加上我当时解决问题的时候跟 mod_wsgi 的作者询问一些问题,主要是解决环境配置问题。
https://github.com/GrahamDumpleton/mod_wsgi/issues/215
以后有什么需要的在补充。
apache+mod_wsgi+django 配置
在不完全明白之前,看别人的帖子总是觉得是错的,等到弄懂以后,怎么看都是对的。正题:
安装 mod_wsgi,然后记得在 http.conf 文件里面添加以下一行:
LoadModule wsgi_module modules/mod_wsgi.so
此时的 apache 就是 wsgi 服务器了。也许有人会问什么是 wsgi 服务器。
# -*- coding: utf-8 -*-
from wsgiref import simple_server
def application(environ, start_response):
status = ''200 OK''
output = ''Hello World!''
response_headers = [(''Content-type'', ''text/plain''),
(''Content-Length'', str(len(output)))]
start_response(status, response_headers)
return [output]
# 下面两行就是简单的wsgi服务器
server = simple_server.make_server(''localhost'', 8080, application)
server.serve_forever()
注意这行:
server = simple_server.make_server(''localhost'', 8080, application)
的参数 application。这在 apache 里肯定无法编译进去,所以需要你在你的虚拟主机配置文件的
WSGIScriptAlias / /path/to/your/main.wsgi
行指出,而文件 /path/to/your/main.wsgi 的内容可能如下:
def application(environ, start_response):
status = ''200 OK''
output = ''<h1>Hello World!</h1>''
response_headers = [(''Content-type'', ''text/plain''),
(''Content-Length'', str(len(output)))]
start_response(status, response_headers)
return [output]
或者
WSGIScriptAlias / /path/to/your/site/wsgi.py
然后 wsgi.py 就是 django 自动生成的文件。
apache和mod_wsgi的多个django网站
我想举办它使用Debian的5同一服务器下的几个场所,说我有site1,site2
和site3
,并承担我的IP是155.55.55.1:
site1: 155.55.55.1:80,script at /opt/django/site1/
site2: 155.55.55.1:8080,script at /opt/django/site2/
site3: 155.55.55.1:8090,script at /opt/django/site3/
这是我的默认Apache:
<VirtualHost *:80>
ServerName /
ServerAlias */
DocumentRoot /opt/django/site1/
LogLevel warn
WSGIScriptAlias / /opt/django/site1/apache/django.wsgi
Alias /media /opt/django/site1/media/statics
Alias /admin_media /home/myuser/Django-1.1/django/contrib/admin/media
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/usr/share/phpmyadmin"
ServerName /phpmyadmin
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
这是我的wsgi配置site1
,位于/opt/django/site1/apache/django.wsgi:
import os,sys
import django.core.handlers.wsgi
sys.path.append('/opt/django')
sys.path.append('/opt/django/site1')
os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
application = django.core.handlers.wsgi.WSGIHandler()
如何添加site2
和site3
,它们是基于Django
的网站,将像一样提供服务site1
?
关于使用mod_wsgi安装Django和wemod安装的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Apache Django Mod_Wsgi – 自动重载、apache+mod_wsgi+django 的环境配置、apache+mod_wsgi+django 配置、apache和mod_wsgi的多个django网站等相关知识的信息别忘了在本站进行查找喔。
本文标签: