微星影驰七彩虹,技嘉,七彩虹,影驰,那个牌子显卡好?谢谢

当前位置:&>&&>&
Apache服务器上部署django运行环境
发布时间:
来源:服务器之家
目前,Apache和mod_python是在生产服务器上部署Django的最健壮搭配。mod_python 是一个在Apache中嵌入Python的Apache插件,它在服务器启动时将Python代码加载到内存中。
Django 需要Apaceh 2.x 和mod_python 3.x支持。
Apache的配置参见:
使用mod_python部署
1.为了配置基于 mod_python 的 Django,首先要安装有可用的 mod_python 模块的
2.然后应该有一个 LoadModule 指令在 Apache 配置文件中。 它看起来就像是这样:
LoadModule&python_module&/usr/lib/apache2/modules/mod_python.so
3.配置Apache,用来定位请求URL到Django应用:
&VirtualHost&*:80&
ServerName&
&Location&"/python1"&
SetHandler&pythonprogram
PythonHandler&django.core.handlers.modpython
SetEnv&DJANGO_SETTINGS_MODULE&python1.settings
PythonAutoReload&Off
PythonDebug&Off
PythonPath&"['/var/www/html/python1']&+&sys.path"
PythonInterpreter&python1
&/Location&
&Location&"/python2"&
SetHandler&pythonprogram
PythonHandler&django.core.handlers.modpython
SetEnv&DJANGO_SETTINGS_MODULE&python2.settings
PythonAutoReload&Off
PythonDebug&Off
PythonPath&"['/var/www/html/python2']&+&sys.path"
PythonInterpreter&python2
&/Location&
&/VirtualHost&
它告诉 Apache,任何在 / python这个路径之后的 URL 都使用 Django 的 mod_python 来处理。
它 将DJANGO_SETTINGS_MODULE 的值传递过去,使得 mod_python 知道这时应该使用哪个配置。
查看 mod_python 文档获得详细的指令列表。
4.重启Apache,查看/python:
/etc/init.d/apache2&restart
使用mod_wsgi部署
1.下载安装 &模块,生成mod_wsgi.so和wsgi.conf
2.在配置中加载模块:
LoadModule&python_module&/usr/lib/apache2/modules/mod_wsgi.so
3.修改Apache配置文件httpd.conf
&VirtualHost&*:80&
ServerName&www.server110
DocumentRoot&/var/www/html/python
WSGIScriptAlias&/&/var/www/html/python/apache/django.wsgi
&Directory&/&
Order&deny,allow
Allow&from&all
&/Directory&
&Directory&/apache&
Allow&from&all
&/Directory&
&/VirtualHost&
4.创建并配置wsgi的配置文件:
#&filename:python.apache.django.wsgi
import&os,&sys
#Calculate&the&path&based&on&the&location&of&the&WSGI&script.
apache_configuration=&os.path.dirname(__file__)
project&=&os.path.dirname(apache_configuration)
workspace&=&os.path.dirname(project)
sys.path.append(workspace)
os.environ['DJANGO_SETTINGS_MODULE']&=&'python.settings'
os.environ['PYTHON_EGG_CACHE']&=&'/tmp'
import&django.core.handlers.wsgi
application&=&django.core.handlers.wsgi.WSGIHandler()
print&&&&sys.stderr,&sys.path&&&&
shell&chmod&a+x&django.wsgi
5.修改Django项目配置文件settings.py:
DATABASES&=&{
'default':&{
'ENGINE':&'django.db.backends.mysql',
'NAME':&'python',&&&&&&&&&&&&&&&&&&&&&
'USER':&'admin',&&&&&&&&&&&&&&&&&&&&&&
'PASSWORD':&'admin123',&&&&&&&&&&&&&&&&&&
'HOST':&'127.0.0.1',&&&&&&&&&&&&&&&&&&&&&
'PORT':&'3306',&}
TEMPLATE_DIRS&=&(
'/var/www/html/python/templates',
6.重启Apache,访问/python
/etc/init.d/apache2&restart
Copyright © . 版权所有1212人阅读
Python & Django(31)
Web Service(12)
操作系统:Ubuntu 12.04
Web服务器:Apache 2.2
Python版本:Python 2.7.3
Django版本:Django 1.4.3
首先使用django-admin命令创建好自己的Django工程,在我的系统中执行完此命令出现一个工程目录(工程名为mpsite),结构如下:
__init.py__
settings.py
新建一个mpsite/mpsite/下新建一个目录wsgi,在wsgi目录中新建文件django.wsgi内容如下:
import sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace=os.path.dirname(project)
sys.path.append(workspace)
os.environ['DJANGO_SETTINGS_MODULE']='mpsite.settings'
os.environ['PYTHON_EGG_CACHE']='/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()保存后退出。
在Apache服务器的配置目录下找到conf.d目录,在下面新建一个文件,内容如下:
WSGIScriptAlias / /usr/share/mpsite/mpsite/wsgi/django.wsgi
&Directory /usr/share/mpsite/mpsite&
Order allow,deny
Allow from all
&/Directory&
&Directory /usr/share/mpsite/mpsite/wsgi&
Allow from all
&/Directory&重启Apache服务器后,访问成功。
其实依照文章中所述也是可以部署成功的,这里只是举个例子,大家只要按照这种逻辑做好配置即可。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:141456次
积分:1801
积分:1801
排名:第17866名
原创:40篇
转载:33篇
译文:14篇
(2)(4)(2)(9)(2)(1)(1)(3)(1)(1)(1)(2)(1)(7)(1)(5)(3)(1)(2)(7)(4)(3)(4)(4)(1)(10)(3)(1)(1)> 博客详情
最近在忙着部署前段时间开发的项目,由于没有注意django的版本问题;在部署时费了老大劲,为逝去的青春留下一页博客。
mod_python部署的方式在django的1.4及1.4之前是可以的,但是从django1.5开始,废弃了这种方式,django官网推荐使用wsgi方式;官方声明如下:
If you’re new to deploying Django and/or Python, we’d recommend you try&&first. In most cases it’ll be the easiest, fastest, and most stable deployment choice.
&discusses deployment and especially scaling in more detail. However, note that this edition was written against Django version 1.1 and has not been updated sincemod_python&was first deprecated, then completely removed in Django 1.5.
以此提醒那些误入歧途的人....
人打赏支持
码字总数 57889
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥
& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区

我要回帖

更多关于 微星影驰七彩虹 的文章

 

随机推荐