自動化運維web環境搭建:Nginx+Django+uwsgi

參考資料:html

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

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

 

安裝環境:nginx

操做系統:redhat6.4django

localhost:192.168.20.183app

 

建立安裝目錄:socket

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/
相關文章
相關標籤/搜索