Django Mezzanine uwsgi nginx 配置

高洛峰
高洛峰 原创
2016-10-17 13:52:46 977浏览

1, mezzanine介绍

mezzanine就是一个基于Django框架的应用, 详细可以参考官方网站:http://mezzanine.jupo.org/

2, Mezzanine 安装指南:

# Install from PyPI  
$ pip install mezzanine  
   
# Create a project  
$ mezzanine-project myproject  
$ cd myproject  
   
# Create a database  
$ python manage.py createdb  
   
# Run the web server  
$ python manage.py runserver

新建的项目如果要修改主题可以参考:https://github.com/renyi/mezzanine-themes.git

3,修改 nginx的配置文件

到你的 nginx 安装目录下的 conf目录下 修改配置文件 nginx.conf.

**** 关于部署由于之前静态文件的设置问题

   
cd  /usr/local/nginx/conf/  
gedit  nginx.conf

添加如下内容:

注意 修改你对应项目的路径 比如 alias /home/daniel/myblog/static;

 server {   
        listen  8080;   
       server_name 123456;   
      
       location / {   
 root /home/daniel/myblog/;  
          uwsgi_pass   127.0.0.1:8000;   
          include     uwsgi_params;   
     }  
location /static {    
    autoindex on;    
    alias /home/daniel/myblog/static;    
    access_log off;    
    log_not_found off;    
}    
location /robots.txt {    
    alias /home/daniel/myblog/static;      
    access_log off;    
    log_not_found off;    
}  
location /favicon.ico {    
    alias /home/daniel/myblog/static/img;    
    access_log off;    
    log_not_found off;    
}   
    
}

至于部署方式可以采用,uWSGI,http://projects.unbit.it/downloads/。

tar zxvf uwsgi-latest.tar.gz  
cd uwsgi-1.2.6  
make  
cp uwsgi  /usr/sbin/uwsgi

安装完uWSGI。

在你的工程目录下新建文件 django_wsgi.py

添加如下内容:

#!/usr/bin/env python  
# coding: utf-8  
import os,sys    
if not os.path.dirname(__file__) in sys.path[:1]:  
    sys.path.insert(0, os.path.dirname(__file__))    
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'    
from django.core.handlers.wsgi import WSGIHandler    
application = WSGIHandler()

新建文件django.xml

添加如下内容,注意修改为自己的路径:

  
     127.0.0.1:8000  
     true  
     /home/daniel/myblog    
     ..  
    django_wsgi.py  
     true  
 

最后运行: wsgi -x wsgi.xml

这是 配置好了,在浏览器输入: http://localhost:8080/

是不是能够浏览你的站点了。

具体配置可参见我的工程里的相关配置

https://github.com/ustcdane/Mezzanine-uwsgi-nginx


文章转自: http://blog.csdn.net/daniel_ustc/article/details/8855303


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。