博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ubuntu不在python虚拟环境下使用uwsgi启动django及nginx代理配置
阅读量:4287 次
发布时间:2019-05-27

本文共 1678 字,大约阅读时间需要 5 分钟。

1.Uwsgi基本安装配置

1).环境描述

    系统环境:ubuntu

    Python环境:python2.7

2).django及uwsgi安装

  1. pip install django
  2. pip install uwsgi

3).测试uwsgi

    编辑vi /home/test.py

# test.py

def application(env, start_response):

    start_response('200 OK', [('Content-Type','text/html')])

    #return [b"Hello World"] # python3

    return ["Hello World"] # python2

    启动命令uwsgi --http-socket :9000 --plugin python --wsgi-file test.py

    使用浏览器访问测试:http://127.0.0.1:9000/

    返回结果:

   

4).一些启动命令的报错及原因:

    使用uwsgi --http 127.0.0.1:9000 --wsgi-file test.py命令启动时,报:

    uwsgi: option '--http' is ambiguous;

   

    问题根源是没有这个uwsgi插件应该使用 --http-socket  参数

    使用命令:uwsgi --http-socket 127.0.0.1:9000 --wsgi-file test.py启动时报:

    uwsgi: unrecognized option '--wsgi-file'

    getopt_long() error

   

    问题原因:uwsgi不识别后面的wsgi  python文件,无法解析

    解决方式:在--wsgi-file 参数前加上--plugin python 参数,告诉uwsgi使用python插件解析后面的python文件

    uwsgi --http-socket :9000 --plugin python --wsgi-file test.py

2.不使用虚拟环境的情况下,Ubuntu创建django项目及nginx服务代理

    1).安装django

   

    2).创建一个django项目

   

    添加view.py文件

   

    修改urls.py文件:

   

   

    执行:python manage.py migrate

   

    运行项目:

   

    浏览器访问测试:

   

3).使用uwsgi命令启动django

     uwsgi --http-socket :8000 --plugin python --wsgi-file helloWord2/wsgi.py

   

4).Uwsgi使用配置文件启动django

    编辑uwsgi启动配置文件:vim /home/uwsgi.ini

[uwsgi]

http-socket = :8000

#the local unix socket file than commnuincate to Nginx

socket = 127.0.0.1:8001

# the base directory (full path)

#chdir = /root/workplace/helloworld

#home = /root/Env/first

# Django's wsgi file

plugin = python

wsgi-file = helloWord2/wsgi.py

# maximum number of worker processes

processes = 4

#thread numbers startched in each worker process

threads = 2

#monitor uwsgi status

stats = 127.0.0.1:9191

# clear environment on exit

#vacuum          = true

    启动运行: uwsgi /home/uswgi.ini

   

   

    5).使用nginx动态代理uwsgi接口,请查看上一篇文章配置

转载地址:http://nzagi.baihongyu.com/

你可能感兴趣的文章
论文笔记|Bidirectional LSTM-CRF Models for Sequence Tagging
查看>>
论文笔记:Constructing Narrative Event Evolutionary Graph for Script Event Prediction
查看>>
论文笔记: Hierarchical Chinese Legal event extraction via Pedal Attention Mechanism
查看>>
论文笔记 | Enhancing Pre-Trained Language Representations with Rich Knowledge for MRC
查看>>
论文笔记 | Text Summarization with Pretrained Encoders
查看>>
论文笔记:Document-level Event Extraction via Heterogeneous Graph-based Interaction Model with a Tracker
查看>>
论文笔记丨Inductive Unsupervised Domain Adaptation for Few-Shot Classification via Clustering
查看>>
论文笔记|GSum: A General Framework for Guided Neural Abstractive Summarization
查看>>
论文笔记 | Does Structure Matter? Encoding Documents for Machine Reading Comprehension
查看>>
论文笔记|Self-Supervised Test-Time Learning for Reading Comprehension
查看>>
论文笔记|Open-world Learning and Application to Product Classification
查看>>
论文笔记 _ ELECTRA_ Pre-training Text Encoders as Discriminators Rather than Generators
查看>>
【论文笔记】
查看>>
论文笔记:Exploring Pre-trained Language Models for Event Extraction and Generation
查看>>
论文解读 | QANET: COMBINING LOCAL CONVOLUTION WITH GLOBAL SELF-ATTENTION FOR READING COMPREHENSION
查看>>
linux 安装nginx
查看>>
linux 搭建rocketmq集群
查看>>
linux 安装zookeeper集群
查看>>
RocketMq单机安装(Windows)
查看>>
Windows 上安装 MySQL
查看>>