Maison  >  Article  >  développement back-end  >  Nginx+uWsgi+Django

Nginx+uWsgi+Django

WBOY
WBOYoriginal
2016-07-30 13:30:46933parcourir

Nginx+uWsgi+Django
系统环境:Ubuntu 14.04LTS

Nginx

官网:http://nginx.org/

安装

1. 系统安装

<code><span>$sudo</span> apt<span>-get</span> install nginx</code>

2. 源码安装

官网下载源码包:建议下载稳定版
地址:http://nginx.org/en/download.html
安装依赖库

解压,配置,编译,安装

<code><span>$tar</span> zxvf nginx<span>-</span><span>1.8</span><span>.0</span><span>.</span>tar<span>.</span>gz
<span>$cd</span> nginx<span>-</span><span>1.8</span><span>.0</span>
$<span>.</span>/configure <span>--</span><span>with</span><span>-pcre</span><span>--</span><span>with</span><span>-http_ssl_module</span><span>--</span><span>with</span><span>-http_realip_module</span><span>--</span><span>with</span><span>-http_gzip_static_module</span><span>--</span><span>with</span><span>-http_secure_link_module</span><span>--</span><span>with</span><span>-http_stub_status_module</span><span>--</span><span>with</span><span>-debug</span><span>$make</span><span>$sudo</span> make install</code>

通过命令查看安装地址:

<code>whereis nginx</code>

默认安装路径为:/usr/local/nginx
在启动时nignx是遇到命令无法识别,发现是nginx模块未安装全

<code><span>$sudo</span> apt<span>-get</span> install nginx<span>-core</span></code>

然后启动nginx

<code><span>sudo</span> nginx</code>

通过浏览器访问http://localhost:80
nginx默认的设置界面即表示启动成功
Welcome to nginx

3. nginx配置文件夹

conf : /usr/local/nginx/conf

相关命令

启动:

<code><span>$sudo</span> nginx 
<span>#$sudo nginx -s start</span></code>

关闭:

<code><span>$sudo</span> nginx <span>-s</span> stop</code>

重启:

<code><span>$sudo</span> nginx <span>-s</span> reload</code>

uWSGI

安装教程:http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html

1. 安装

<code><span>$sudo</span> apt<span>-get</span> install uwsgi<span>-plugin</span><span>-python</span><span>$sudo</span> apt<span>-get</span> install uwsgi</code>

源码安装

下载:http://projects.unbit.it/uwsgi/wiki/WikiStart
解压,配置,编译,安装

<code><span>$tar</span> zxvf uwsgi-<span>2.0</span><span>.6</span>.tar.gz
<span>$cd</span> uwsgi-<span>2.0</span><span>.6</span><span>$sudo</span><span>python</span> setup.py install</code>

当安装完成后,会提示end of uWSGI configration

测试uWSGI

打印版本信息

<code><span>$uwsgi</span> --version</code>

编写测试脚本,test.py

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

启动uWSGI,使用未占用端口

<code><span>$uwsgi</span><span>-</span><span>-</span><span>http</span><span>:9090</span><span>-</span><span>-</span><span>wsgi</span><span>-</span><span>file</span><span>test</span><span>.</span><span>py</span></code>

在浏览器输入地址访问

<code>http:<span>//localhost:9090/</span></code>

浏览器输出 Hello World,表示安装成功

相关命令

启动:
执行相应脚本
关闭:

<code><span>$killall</span><span>-</span><span>9</span> uwsgi
<span>$killall</span><span>-s</span> HUP /<span>var</span>/www/uwsgi 
<span>$killall</span><span>-s</span> HUP /usr/<span>local</span>/bin/uwsgi
</code>

Django

安装依赖库

<code><span>$sudo</span> apt<span>-get</span> install python2<span>.7</span></code>

安装Django

下载源码:https://www.djangoproject.com/download/
解压,配置,编译,安装

<code><span>$tar</span> zxvf Django-<span>1.8</span><span>.4</span>.tar.gz
<span>$cd</span> Django-<span>1.8</span><span>.4</span><span>$sudo</span><span>python</span> setup.py install</code>

测试Django

打印Django版本信息

<code><span>$python</span><span>>></span><span>import</span> django
<span>>></span>django<span>.</span>VERSION
(<span>1</span>,<span>8</span>,<span>4</span>, <span>'final'</span>, <span>0</span>)</code>

当出现如上显示时,说明Django安装成功

参考

http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
http://segmentfault.com/q/1010000002523354
http://www.nowamagic.net/academy/detail/1330331
http://www.nowamagic.net/academy/detail/1330334
http://www.linuxidc.com/Linux/2014-09/106928.htm

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Nginx+uWsgi+Django,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn