首页 > 其他 > 详细

uwsgi启动Django应用

时间:2020-09-23 17:35:36      阅读:201      评论:0      收藏:0      [点我收藏+]

uwsgi启动Django应用

 

uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。

 WSGI / uwsgi / uWSGI 三者区别:

WSGI是一种通信协议,Flask,webpy,Django、CherryPy等等都自带WSGI,不过性能都不好。

uwsgi同WSGI一样是一种通信协议。

uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。

1.安装uWSGI

pip install uwsgi

2.查找安装的uwsgi位置

find / -name uwsgi

3.建立一个软连接

ln -r uwsgilujing  /usr/bin/uwsgi

4.在应用目录,也就是manage.py所在目录下

技术分享图片
 

vi uwsgi.ini[uwsgi]

#使用nginx连接时使用,Django程序所在服务器地址

# socket=ip:80

#直接做web服务器使用,Django程序所在服务器地址

http=ip:80    注意:我用的腾讯云服务器,ip填写的是内网地址,不然报错bind(): Cannot assign requested address [core/socket.c line 769]

#项目目录

chdir=/root/program/WxFindInfo/mysite/

#项目中wsgi.py文件的目录,相对于项目目录

wsgi-file=mysite/wsgi.py

# 进程数

processes=4

# 线程数

threads=2

# uwsgi服务器的角色

master=True

# 存放进程编号的文件

pidfile=uwsgi.pid

# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的

daemonize=uwsgi.log

5.启动uWSGI服务器

uwsgi --ini uwsgi.ini 

6.停止

uwsgi --stop uwsgi.pid/kill -9 pid

7.重启

uwsgi --reload uwsgi.pid

 
# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir =    /root/logsystem
# Djangos wsgi file
#module = myshop.wsgi #testd????????????testd.wsgi????????涨??д?????????????
module= logsystem.wsgi:application
#static-map = /static=/root/logsystem/all_static_collect
buffer-size = 65536
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe
socket = 127.0.0.1:8081
#http= 192.168.8.192:8081
#http-socket = 192.168.8.192:8081
#http://60.205.211.11 172.17.36.8
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
#http-socket = 172.17.36.8:8081
enable-threads = true
mule = common/dbutil.py
vacuum = true
user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  $remote_addr - $remote_user [$time_local] "$request" 
    #                  $status $body_bytes_sent "$http_referer" 
    #                  "$http_user_agent" "$http_x_forwarded_for";

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
    upstream django {
                #server unix:///path/to/your/mysite/mysite.sock; # 
                 server 127.0.0.1:8080;  # 8081
    }


    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            include /usr/local/nginx/conf/uwsgi_params;
            uwsgi_pass  django;
        }
        
        
      location /static/{
        alias  /root/logsystem/static_collect/;
        expires 30d;
        autoindex on;
      }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apaches document root
        # concurs with nginxs one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

uwsgi启动Django应用

原文:https://www.cnblogs.com/xiao-xue-di/p/13719359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!