自动化运维web环境搭建:Nginx+Django+uwsgi

参考资料:

http://lovelace.blog.51cto.com/1028430/1600594

http://www.cnblogs.com/xiongpq/p/3381069.html

安装环境:

操作系统:redhat6.4

localhost:192.168.20.183

创建安装目录:

mkdir -p /home/install/Django && cd /home/install/Django
mkdir -p /data/logs/
 
redhat的话需要安装配置yum环境
卸载现有yum:rpm -qa | grep yum | xargs rpm -e --nodeps
 
http://www.th7.cn/system/lin/201309/44654.shtml
yum安装过程见以上链接即可。
 
安装nginx
wget http://nginx.org/download/nginx-1.6.3.tar.gz
 
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-cc-opt='-03' --with-cpu-opt=opteron
 
报pcre错误:
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install MySQL-python
 
安装uwsgi
 
wget http://projects.unbit.it/downloads/uwsgi-2.0.12.tar.gz
tar -zxvf uwsgi-2.0.12.tar.gz
cd uwsgi
python setup.py build
python setup.py install
 
出现报错:plugins/python/python_plugin.c:1862: error:
安装python-devel
 
##################################
def application(env, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return "Hello World"
##################################  test.py
 
uwsgi --http :8001 --wsgi-file test.py
 
 
在data/www/下创建omswanbu项目
django-admin.py startproject omswanbu
 
配置uwsgi:
在/usr/local/nginx/conf/下创建uwsgi.ini配置文件,内容如下:
[uwsgi]
socket = 0.0.0.0:9000
master = true
pidfile = /usr/local/nginx/uwsgi.pid
processes = 8
chdir = /data/www/omswanbu
env = DJANGO_SETTINGS_MODULE=omswanbu.settings
module = django.core.handlers.wsgi:WSGIHandler()
pythonpath = /data/www
profiler = true
memory-report = true
enable-threads = true
logdate = true
limit-as = 6048
daemonize = /data/logs/django.log
 
配置nginx:
server {
        listen       80;
        server_name  192.168.20.183;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            uwsgi_pass 192.168.20.183:9000;
            include uwsgi_params;
            uwsgi_param UWSGI_CHDIR /data/www/omswanbu;
            uwsgi_param UWSGI_SCRIPT omswanbu.wsgi;       #创建项目下的wsgi.py文件,"omswanbu."代表的是路径
            access_log off;
        }
        location ^~ /static {
            root /data/www/omswanbu;
        }
 
        location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bg2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg)$ {
            root /data/www/omswanbu/static;
            access_log off;
        }
 
启动uwsgi:
/usr/bin/uwsgi --ini /data/www/omswanbu/prod.ini
 
启动nginx:/usr/local/nginx/sbin/nginx
 
访问页面:http://192.168.20.183/
上一篇:201521123023《Java程序设计》第9周学习总结


下一篇:pandas读取各类sql数据源