Django部署到Apache Web Server
Windows环境下,将Django部署到Apache Web Server
在Windows上部署Django(用mod_wsgi)会出现各种奇怪的问题,现简单记录下配置过程及遇到的错误及解决方法。
环境搭建
windows 7
python 2.7.3 (注意最好是32位的,因为Apache目前对64位支持非常不友善,尝试了好多次,64位的太高大上,众多不兼容)
Apache2.2.10 (直接下载apache_2.2.10-win32-x86-no_ssl.msi就行)
Django-1.6.1 (官网下载)
配置思路
1、配置apache的httpd.conf文件
2、配置django相关配置文件
配置过程
其实配置生效针对不同的环境有不同的细节需要处理,网上的方案(包括本篇)都不是一定通用的,只是在某种环境下有效,但总体思路就是配置上述提及的两个配置文件。
部署django项目常用的两个方式是使用mod_python和mod_wsgi两种部署方式,这里我使用的是mod_wsgi。
1、先去网上下载个名叫这个的东西:mod_wsgi-3.4.ap22.win32-py2.7,里面有个文件是mod_wsgi.so,然后把这个copy到apache安装目录的modules文件下(默认安装目录是:C:\Program Files (x86)\Apache Software Foundation\Apache2.2\modules)
下面两个配置中涉及路径的很容易搞错,如果是绝对路径的话要检查自己是否正确。
2、在Django项目根目录下新建两个文件:
django.wsgi:
1
2
3
4
5
6
7
8
9
10
11
|
<span style= "font-size: 14px;" >#coding=utf- 8 import os import sys import django.core.handlers.wsgi os.environ[ 'DJANGO_SETTINGS_MODULE' ] = 'appops.settings' app_apth = "D:/OPSAPP/appops" sys.path.append(app_apth) application = django.core.handlers.wsgi.WSGIHandler() </span> |
apache_django_wsgi.conf:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<span style= "font-size: 14px;" >#Alias / D:/OPSAPP/appops Alias /favicon.jpg D:/OPSAPP/appops/ static /images/favicon.jpg #WSGIScriptAlias /api "D:/OPSAPP/appops/appapi/handler.py" #注意,这里在httpd.conf中写过的话这里就不用写了。 WSGIScriptAlias / "D:/OPSAPP/django.wsgi" WSGIPassAuthorization On <Directory "D:/OPSAPP/appops/appops" > Order Deny,Allow Allow from all </Directory> Alias / static / D:/OPSAPP/appops/ static / <Directory D:/OPSAPP/appops/ static / > Order deny,allow Allow from all IndexOptions FancyIndexing </Directory> <Directory D:/OPSAPP/appops/ > Order deny,allow Allow from all IndexOptions FancyIndexing </Directory> <Directory "D:/OPSAPP" > Allow from all </Directory> </span> |
目录结构如下:
3、编辑apache的配置文件httpd.conf(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf)
中间加上一句:
LoadModule wsgi_module modules/mod_wsgi.so
文件结尾新增下列配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<span style= "font-size: 14px;" >Alias / static D:/OPSAPP/appops/ static #这是为了可以通过url来访问 static 文件 <Location "/static/" > SetHandler None </Location></span><br><span style= "font-size: 14px;" > <VirtualHost *: 80 > #配置虚拟目录 ServerName app.ops.test.com #ServerName 192.168 . 18.74 DocumentRoot D:/OPSAPP WSGIScriptAlias / D:/OPSAPP/django.wsgi <Directory /> Order deny,allow Allow from all </Directory> <Directory /apache> Allow from all </Directory> </VirtualHost> <Directory "D:/OPSAPP/appops/static/" > #这个一定需要,不然网页样式错误,css没有起作用 Order Deny,Allow Allow from all </Directory> </span> |
重启下apache服务基本就OK了。
常见错误
访问失败时的错误会记录在apache日志里(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\logs),
1、静态资源不能访问,如css样式错乱等,需要在httpd.conf文件里增加配置:
1
2
3
4
5
6
|
<span style= "font-size: 14px;" ><Directory D:/OPSAPP/appops/ static / > Order deny,allow Allow from all IndexOptions FancyIndexing </Directory> </span> |
2、出现找不到模块的错,如no module named XXX等,主要有两个原因:
1)、路径错了
2)、文件命名跟Django或python内部模块冲突了
参考:
http://www.cnblogs.com/zhengyun_ustc/archive/2006/11/20/django_apache_win32.html
http://www.server110.com/apache/201309/1873.html
Django部署到Apache Web Server的更多相关文章
- Windows环境下,将Django部署到Apache Web Server
在Windows上部署Django(用mod_wsgi)会出现各种奇怪的问题,现简单记录下配置过程及遇到的错误及解决方法. 环境搭建 ...
- Using Apache Web Server with Jboss AS 7
In real-world projects, it's common to find Apache web server as a front door to your application se ...
- 解决Apache Web Server的几个错误
一.安装好Apache后服务里没有Apache服务 在命令行进入安装apache的bin目录下,输入命令 httpd.exe -k install -n Apache2.4 二.Apache web ...
- yum安装Apache Web Server后各个文件存放位置
yum安装Apache Web Server后各个文件存放位置 用yum安装apache软件: yum -y install httpd 安装完成后,来查看理解yum安装软件的过程和安装路径. ...
- django部署到apache上(非常重要的,3者版本要一致,是32位就都要是32位的)
网上把django部署到apache的文章挺多的,但是按照大家的操作,并没有一次就成功,还是遇到了一些问题,这里主要有以下几个情况. 1.网上找到的mod_wsgi的版本问题,导致动态库加载不上. 2 ...
- django 部署到 apache
安装完django之后,每次都需要通过命令来启动启动开发服务器.虽然调试和测试方便,但只能在本地运行,并且不能承受许多用户同时使用的负载.所以需要将Django部署到生产级的服务器,这里选择apach ...
- kill 挂起 Apache Web Server
[root@hadoop1 ~]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8 ...
- 如何将Django部署到Apache服务器上
操作环境: Ubuntu 16.04 Apache 2.4 Django 1.9 Python 2.7 mod_wsgi 前言:本教程纯自己查阅资料后整理,望对大家有帮助! 1. 安装 mod_ws ...
- 禁掉Apache web server签名 How to turn off server signature on Apache web server
有的时候,我们为了从安全角度考虑,防止黑客恶意攻击.我们会隐藏掉server信息,比方,一般我们会发现例如以下信息. 我用的是centos (fedora, RHEL也一样) $ sudo vi /e ...
随机推荐
- HDU 4085 Steiner树
主题链接:pid=4085">http://acm.hdu.edu.cn/showproblem.php? pid=4085 由于这题专门花一晚上学习斯坦纳树.找到比較好的学习资料,链 ...
- TCP/IP的经典网络编程
TCP/IP网络编程之四书五经 ...
- 使用Eclipse+Maven+Jetty构建Java Web开发环境(几个教程综合集成2014发行)
工作需要使用Jetty由于web集装箱,得知Eclipse+Maven+Jetty该组合是非常好的,因此,要在网上找了很多教程,但不写或多或少特定的或过时的内容而导致最终的配置失败,易于配置为未来的同 ...
- 《代码的第一行——Android》封面诞生
<代码的第一行--Android>已经上市近一个月,现在的情况是相当不错的销售,也特别感谢众多朋友的支持. 其实一本好书,假设你想卖.除了给予外力所要求的内容.封面设计是至关重要的,这本书 ...
- Chapter 2 User Authentication, Authorization, and Security(3):保server避免暴力袭击
原版的:http://blog.csdn.net/dba_huangzj/article/details/38756693,专题文件夹:http://blog.csdn.net/dba_huangzj ...
- ScrollView 嵌套ListView 幻灯冲突,和显示不全
import android.content.Context; import android.util.AttributeSet; import android.widget.ListView; /* ...
- 经常使用git命令集
//创建本地仓库 mkdir git_root;cd git_root;git init // //查看 git status . git log git log ./kernel/driver/ g ...
- Linux线程 之 线程 线程组 进程 轻量级进程(LWP)
Thread Local Storage,线程本地存储,大神Ulrich Drepper有篇PDF文档是讲TLS的,我曾经努力过三次尝试搞清楚TLS的原理,均没有彻底搞清楚.这一次是第三次,我沉浸gl ...
- Linux中加入用户、删除用户时新手可能遇到的问题
Linux中加入用户.删除用户时新手可能遇到的问题 1.创建新用户后切换到新用户:No directory, logging in with HOME=/ 加入用户 #sudo us ...
- JavaScript中的单引号和双引号报错的解决方法
在使用JavaScript显示消息或者传递字符数据的时候,经常会碰到数据中夹杂单引号(')或者双引号("),这种语句往往会造成JavaScript报错.对此一般采用/'或者/"的解 ...