Latest web development tutorials

ジャンゴnginxの+ uwsgiのインストールと構成

前の節では、サーバーを実行するためのpython manage.pyののrunserverを使用しています。 これは、テスト環境のみに適用されます。

公式リリースサービスは、我々はそのような本は、nginxの例になるなどのapache、nginxの、lighttpdの、として、安定的かつ継続的なサーバーが必要です。


インストールベースの開発キット

次のようにCentOSにはインストール:

yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

CentOSのは、Python 2.4.3が付属していますが、私たちはPython2.7.5をインストールすることができます。

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

Pythonのパッケージマネージャをインストールします。

easy_installをパッケージhttps://pypi.python.org/pypi/distribute

インストール手順:

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パッケージ: https://pypi.python.org/pypi/pip

利点は、あなたがピップピップリスト、ピップアンインストールPythonのパッケージ管理をインストールすることができることである、easy_installをのみ、アンインストール、この機能を持っていません。


インストールuwsgi

uwsgi: https://pypi.python.org/pypi/uWSGI

詳細uwsgi引数: http://uwsgi-docs.readthedocs.org/en/latest/Options.html

pip install uwsgi
uwsgi --version    #查看 uwsgi 版本

Uwsgiテストは正常です。

新しいtest.pyファイル、次のように:

def application(env, start_response):
	start_response('200 OK', [('Content-Type','text/html')])
	return "Hello World"

その後、ターミナルで実行されています:

uwsgi --http :8001 --wsgi-file test.py

ブラウザに入力します。http://127.0.0.1:8001を、出力がない場合は、インストールプロセスを確認してください、「Hello World」の出力があるかどうかを確認します。


ジャンゴをインストール

pip install django

Djangoのテストが正常である、実行します。

django-admin.py startproject demosite
cd demosite
python2.7 manage.py runserver 0.0.0.0:8002

ジャンゴが正常に動作している確認し、8002ます:http://127.0.0.1ブラウザに入力します。


nginxのをインストールします。

次のようにコマンドをインストールします。

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

あなたが読むことができるnginxのインストール構成を詳細をご覧ください。


uwsgi設定

uwsgiは、本論文では、iniファイル、例えば、新しいuwsgi9090.ini /電気ショック療法/ディレクトリの下などの設定のiniファイル、XML、の様々なサポート、次の設定を追加します:

[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の設定

見つかったnginxのインストールディレクトリ(例:は/ usr / local / nginxの/)、オープンのconf / nginx.confファイル、サーバの設定を変更します。

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;
        }
    }

あなたが読むことができるnginxのインストール構成を詳細をご覧ください。

ターミナルで実行して、設定した後:

uwsgi --ini /etc/uwsgi9090.ini &
/usr/local/nginx/sbin/nginx

ます。http:ブラウザに入力し//127.0.0.1、あなたはジャンゴアップ "それは仕事をする」を参照してくださいすることができます。