django部署实录

阿里云使用apache+mod_wsgi进行django的部署

 

最终救星:http://blog.chedushi.com/archives/4692 

 

1、

http://www.it165.net/admin/html/201312/2234.html

使用了virtualhost:同一个ip使用不同的端口来serve不同的网站(apache官方文档有示例)

Running different sites on different ports.

You have multiple domains going to the same IP and also want to serve multiple ports. The example below illustrates that the name-matching takes place after the best matching IP address and port combination is determined.

Listen 80

Listen 8080

 

<VirtualHost 172.20.30.40:80>

    ServerName www.example.com

    DocumentRoot /www/domain-80

</VirtualHost>

 

<VirtualHost 172.20.30.40:8080>

    ServerName www.example.com

    DocumentRoot /www/domain-8080

</VirtualHost>

 

<VirtualHost 172.20.30.40:80>

    ServerName www.example.org

    DocumentRoot /www/otherdomain-80

</VirtualHost>

 

<VirtualHost 172.20.30.40:8080>

    ServerName www.example.org

    DocumentRoot /www/otherdomain-8080

</VirtualHost>

 

http://greybeard.iteye.com/blog/1564975l里面有

 

WSGIScriptAlias / "/usr/bigbang/stargazerservice/django.wsgi" 

 

于是我在<VirtualHost 121.40.135.166:8080>(第二个端口的网站)里面加入:

WSGIScriptAlias "/" "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/zzc/zzc/zzc/wsgi.py"

 

<VirtualHost 121.40.135.166:8080>中添加:

Alias "/static/" "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/zzc/zzc/static/"

 

直接将static url作为目录来处理,这样子访问里面所有的文件都由服务器作为静态文件处理,于是就搞定了!

 

大概解决过程是这样,原理之后再补。

 

其他记录:

1、

Apache Virtual Host documentation

里面有apache的两种虚拟主机方案:

 

一般选择使用name-based的,这样可以节省珍贵的ip资源

 

name-based可以通过开启:

LoadModule vhost_alias_module modules/mod_vhost_alias.so

和:

Include conf/extra/httpd-vhosts.conf

并且通过:

listen port1 

listen port2

lisetn ….

开启!

 

2、http://www.neoease.com/apache-virtual-host/ 开启virtual host的方式

 

3、git版本管理可以让你不记得之前可以运行的代码已经没有了的时候可以上去版本库去看!

 

4、urlpattern有什么用?看django文档:

This helper function will only work if DEBUG is True and your STATIC_URL setting is neither empty nor a full URL such as http://static.example.com/.

 

5、This directive currently has no effect.。。。。。。。。。。。

 

6、mod_wsgi分析:

http://a-journey-into-python-source.readthedocs.org/en/latest/100.html  超级具体的分析

 

WSGI: 一个协议,描述通用服务器与python app之间的接口规范

wsgi app:遵守wsgi规范的python app

mod_wsgi: apache服务器的一个扩展模块, wsgi协议在apache服务器上的一个实现,有了它, 你就可以在apache上运行wsgi app

总的来说,WSGIScriptAlias 模式,python解释器被嵌入到apache进程当中,请求处理代码是在apache的 worker子进程中执行。WSGIDaemonProcess python解释器运行在单独的进程之中,和apache进程是隔离的。

 

http://a-journey-into-python-source.readthedocs.org/en/latest/index.html# 已suck

 

7、记得自定义virtualhost写各个端口的errorlog和customlog文件

 

posted @ 2014-12-09 04:54  ScutLaozk  阅读(121)  评论(0编辑  收藏  举报