zoukankan      html  css  js  c++  java
  • uWSGI+Django (中)

    环境是ubuntu 14.0 python3  django 1.10

    1:安装uwsgi

    sudo apt-get install libpcre3 libpcre3-dev 

    sudo pip3 install uwsgi 

    顺序必须要这样并且必须要以root的身份不然报错 !!! no internal routing support, rebuild with pcre support !!!

    安装完之后

      1:测试uwsgi

      新建test.py 如下st.py

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

      uwsgi --http :8001 --wsgi-file test.py(这句命令要和test.py在同一位置,如果不在该会报错:failed to open python file test.pyunable to load app 0 (mountpoint='') (callable not found or import error)*** no app loaded. going in full dynamic mode *** )
    打开浏览器输入 127.0.0.1:8000 会显示Hello World
      OK无误

    2:测试uwsgi+django
    首先确保django无误。然后
    uwsgi --http :8000 --module name.wsgi      name为你wsgi所在文件夹的名字     (同理wsgi文件要和命令在同一位置)
    然后在浏览器里访问django



    解释一下:

    WSGI: WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx)与应用服务器(如uWSGI服务器)通信的一种规范。

    uWSGI: uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。 Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

    uwsgi: uwsgi同WSGI一样是一种通信协议,而uWSGI是实现了uWSGI和WSGI两种协议的Web服务器。

    有了uWSGI为什么还需要nginx?

    nginx具备优秀的静态内容处理能力,然后将动态内容转发给uWSGI服务器,这样可以达到很好的客户端响应。

    (以上内容均为网上所看+本人实际操作)
                                                                
  • 相关阅读:
    LeetCode#1047-Remove All Adjacent Duplicates In String-删除字符串中的所有相邻重复项
    LeetCode#345-Reverse Vowels of a String-反转字符串中的元音字母
    LeetCode#344-Reverse String-反转字符串
    LeetCode#232-Implement Queue using Stacks-用栈实现队列
    LeetCode#225-Implement Stack using Queues-用队列实现栈
    LeetCode#20-Valid Parentheses-有效的括号
    树的遍历
    [leetcode] 树(Ⅰ)
    二叉树图形化显示
    你错在成长于文明的边陲
  • 原文地址:https://www.cnblogs.com/mryrs/p/7128576.html
Copyright © 2011-2022 走看看