uwsgi 神器问题

问题简述:编程新手打算用Ubuntu16.04,Python3.5,Django2.0写一个展示数据的简易项目,只有一个App,测试无误,打算用NGINX+uWSGI部署。但是测试过程中出现问题。

先贴下代码

  1. 项目写在/var/www/下,名称onco,建立一个app为current。
  2. setting是这样的(除了数据库,App改了之外,就下边加了关于静态文件的东西):
import os

DEBUG = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
]
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
  1. 在部署uWSGI过程中,用来测试的test.py为:
#!/usr/bin/python

def application(env, start_response):
    start_response('200 OK', [('Content_Type', 'text/html')])
    return [b"Congraduation!!! uWSGI Testing OK!!!"]

使用uwsgi --http :8001 --wsgi-file test测试可以通过,在测试项目的时候使用uwsgi --http :8001 --/var/www/onco --module onco.wsgi也正常通过。

  1. 安装Nginx。80端口访问后出现nginx欢迎界面。
  2. 配置Nginx。在项目目录下建立了myconfig:
upstream django {
        server 127.0.0.1:9002; 
    }
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location /static/ {
        alias /var/www/onco/currenct/static/;
    }

    location / {
        root /var/www/onco; #项目目录
        uwsgi_pass django;
        include /var/www/onco/uwsgi_params; #uwsgi_params文件的地址
    }
}

uwsgi_params文件也写在了这个目录。

  1. 测试运行uwsgi --socket :9002 --wsgi-file test的时候,运行日志:
*** Starting uWSGI 2.0.17.1 (64bit) on [Tue Jul 31 13:10:36 2018] ***
compiled with version: 5.4.0 20160609 on 30 July 2018 04:21:16
os: Linux-4.13.0-36-generic #40~16.04.1-Ubuntu SMP Fri Feb 16 23:25:58 UTC 2018
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /var/www/onco
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3768
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :9002 fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01)  [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1569890
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1569890 pid: 12160 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options

访问界面后网页提示

192.168.0.105 未发送任何数据。
ERR_EMPTY_RESPONSE

后台提示invalid request block size: 21573 (max 4096)...skip
教程告诉我要增大buffer,所以我使用uwsgi --socket :8011 --wsgi-file test.py --buffer-size 32768运行,仍然得到:

192.168.0.105 未发送任何数据。
ERR_EMPTY_RESPONSE

但这次后台提示变成:
uwsgi_proto_uwsgi_parser(): Success [proto/uwsgi.c line 40]

所以测试nginx一直没能往下进行。网上教程说是因为我没有用socket,我不知道是哪个地方配置错了,导致nginx和uwsgi一直无法通信

请各位不吝赐教

阅读 2.3k
评论 更新于 2018-07-31
 
 
1 个回答
老汤
  •  17

我把socket:9002 换成http-socket:9002,加上。。。。
算了,贴上我的uwsgi.ini
[uwsgi]
http-socket = :9000
master = true
enable-threads = true
chdir = /home/proj #
module = proj.wsgi
uwsgi_read_timeout = 600
harakiri =1200
buffer-size = 32768
processes = 4
threads = 4
chmod-socket = 664
vacuum = true

logto =uwsgi.log

limit-as =6048
plugin=python35

pythonpath = /home/proj

socket=/home/proj/log/uwsgi.sock

这个是nginx。conf局部

upstream serverproj {
    server unix:///home/proj/log/uwsgi.sock;#file socket
}

server {

location / {

    uwsgi_send_timeout  600;
    uwsgi_connect_timeout  600;
    uwsgi_read_timeout  2100;
    uwsgi_param UWSGI_CHDIR /home/proj/;
    uwsgi_param UWSGI_SCRIPT proj.wsgi;
        uwsgi_pass serverproj;    
    include /home/proj/uwsgi_params;
    
    }

posted on 2020-02-01 20:59  与非朋仔  阅读(3931)  评论(0编辑  收藏  举报

导航