Django Nginx + uwsgi Installation und Konfiguration
Im vorigen Abschnitt verwenden wir Python manage.py runserver den Server auszuführen. Dies gilt nur für die Testumgebung.
Offizielle Freigabe-Service, brauchen wir eine stabile und kontinuierliche Server wie Apache, Nginx, lighttpd, usw. Dieses Nginx Beispiel sein wird.
Installierte Basis Development Kit
Centos wie folgt installiert:
yum groupinstall "Development tools" yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
CentOS kommt mit Python 2.4.3, aber wir können Python2.7.5 installieren:
cd ~ wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2 tar xvf Python-2.7.5.tar.bz2 cd Python-2.7.5 ./configure --prefix=/usr/local make && make altinstall
Installieren Sie Python Package Manager
easy_install Paket https://pypi.python.org/pypi/distribute
Installationsschritte:
cd ~ wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz tar xf distribute-0.6.49.tar.gz cd distribute-0.6.49 python2.7 setup.py install easy_install --version
Pip - Paket: https://pypi.python.org/pypi/pip
Vorteil ist, dass Sie Pip Liste installieren können, Management pip deinstallieren Python-Paket, hat easy_install nicht über diese Funktion, nur deinstallieren
Die Installation uwsgi
uwsgi: https://pypi.python.org/pypi/uWSGI
uwsgi Argumente aufgeführt: http://uwsgi-docs.readthedocs.org/en/latest/Options.html
pip install uwsgi uwsgi --version #查看 uwsgi 版本
Uwsgi Test ist normal:
New test.py Datei wie folgt:
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return "Hello World"
Dann läuft in einem Terminal:
uwsgi --http :8001 --wsgi-file test.py
Geben Sie im Browser: http: //127.0.0.1: 8001, zu sehen, ob es "Hallo Welt" Ausgang, wenn kein Ausgang ist, überprüfen Sie bitte Ihre Installation.
Installieren Sie Django
pip install django
Django Test normal ist, auszuführen:
django-admin.py startproject demosite cd demosite python2.7 manage.py runserver 0.0.0.0:8002
Geben Sie im Browser: http: //127.0.0.1: 8002, überprüfen django richtig arbeitet.
Installieren Nginx
Installieren Befehl wie folgt:
cd ~ wget http://nginx.org/download/nginx-1.5.6.tar.gz tar xf nginx-1.5.6.tar.gz cd nginx-1.5.6 ./configure --prefix=/usr/local/nginx-1.5.6 \ --with-http_stub_status_module \ --with-http_gzip_static_module make && make install
Sie können lesen , Nginx Installation Konfiguration mehr zu erfahren.
uwsgi Konfiguration
uwsgi unterstützt eine Vielzahl von Konfigurationen ini, XML, etc. In diesem Papier, ini, beispielsweise unter dem neuen uwsgi9090.ini / ect / Verzeichnis, fügen Sie die folgende Konfiguration:
[uwsgi] socket = 127.0.0.1:9090 master = true //主进程 vhost = true //多站模式 no-site = true //多站模式时不设置入口模块和文件 workers = 2 //子进程数 reload-mercy = 10 vacuum = true //退出、重启时清理文件 max-requests = 1000 limit-as = 512 buffer-size = 30000 pidfile = /var/run/uwsgi9090.pid //pid文件,用于下面的脚本启动、停止该进程 daemonize = /website/uwsgi9090.log
Nginx Konfiguration
Gefunden nginx Installationsverzeichnis (zB: / usr / local / nginx /), offene conf / nginx.conf Datei, ändern Sie die Server-Konfiguration:
server { listen 80; server_name localhost; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9090; //必须和uwsgi中的设置一致 uwsgi_param UWSGI_SCRIPT demosite.wsgi; //入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录 uwsgi_param UWSGI_CHDIR /demosite; //项目根目录 index index.html index.htm; client_max_body_size 35m; } }
Sie können lesen , Nginx Installation Konfiguration mehr zu erfahren.
Nach der Einstellung in einem Terminal ausgeführt werden:
uwsgi --ini /etc/uwsgi9090.ini & /usr/local/nginx/sbin/nginx
Geben Sie im Browser: http: //127.0.0.1, können Sie die django sehen "Es funktioniert" auf.