下载安装mod_wsgi
这里我的版本是mod_wsgi-3.4.tar.gz
在django的目录建立一个test.wsgi 这里我的目录是/var/www/html/Simplecmdb
建立一个test.wsgi
1
2
3
4
5
6
7
8
9
|
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]
|
开启apache的虚拟主机
vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
建立测试的配置文件
1
2
3
4
5
6
7
8
9
10
|
cd
/etc/httpd/conf
.d/
vim
test
.conf
<VirtualHost *:80>
WSGIScriptAlias /
"/var/www/html/Simplecmdb/test.wsgi"
<Directory
"/var/www/html/Simplecmdb"
>
Order Deny,Allow
Allow from all
<
/Directory
>
<
/VirtualHost
>
|
重启apache后访问http://ip
出现hello world说明正常
在自己的django项目目录下建立django.wsgi
1
2
3
4
5
6
7
8
9
10
|
#!/usr/bin/env python
#coding: utf-8
import
sys
import
os
sys.path.append(
"/var/www/html/Simplecmdb"
)
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE"
,
"Simplecmdb.settings"
)
from
django.core.wsgi
import
get_wsgi_application
application
=
get_wsgi_application()
|
注意:因为项目文件夹和下面的子文件夹是同个名字,容易搞混,sys.path.append的路径,
到项目文件夹就可以了,否则下一行的“Simplecmdb.settings”将找不到项目的setting.py文
件,而引发“internal server error”.
1
2
3
4
5
6
7
8
9
10
|
cd
/etc/httpd/conf
.d/
vim simplecmdb.conf
LoadModule wsgi_module modules
/mod_wsgi
.so
<VirtualHost *:80>
WSGIScriptAlias /
"/var/www/html/Simplecmdb/django.wsgi"
<Directory
"/var/www/html/Simplecmdb"
>
Order Deny,Allow
Allow from all
<
/Directory
>
<
/VirtualHost
>
|
service httpd restart
访问http://ip/admin
这里django项目的权限要改成apache的运行用户,不然会有报错
本文转自 shouhou2581314 51CTO博客,原文链接:http://blog.51cto.com/thedream/1680462,如需转载请自行联系原作者