Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

nginx uwsgi flask ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

nginx uwsgi flask ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

first time calling get API with response body size-2 MB - data is coming

second time calling get API with response body size-2 MB - error coming - ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

Dockerfile

FROM python:3.7.6

RUN apt-get update
RUN apt-get install -y --no-install-recommends 
        libatlas-base-dev gfortran nginx supervisor

RUN pip3 install uwsgi

RUN useradd --no-create-home nginx

RUN rm /etc/nginx/sites-enabled/default
RUN rm -r /root/.cache


COPY nginx.conf /etc/nginx/
COPY flask-site-nginx.conf /etc/nginx/conf.d/
COPY uwsgi.ini /etc/uwsgi/
COPY supervisord.conf /etc/

flask-site-nginx.conf

server {
  listen       80;
  client_max_body_size 100M;

    location / {
        try_files $uri @application;
        client_max_body_size 100M;
    }
    location @application {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
        uwsgi_read_timeout 17200;
        uwsgi_send_timeout 17200;
        proxy_send_timeout 17200;
        proxy_read_timeout 17200;
        client_max_body_size 100M;
    }
}

nginx.conf

user nginx;

worker_processes auto;

pid /tmp/nginx.pid;

daemon off;

pcre_jit on;
error_log /var/log/nginx/error.log warn;


events {
    worker_connections  1024;
}


http {
    
    include /etc/nginx/mime.types;
    # Define the default file type that is returned to the user
    default_type text/html;

    # Don't tell nginx version to clients.
    server_tokens off;

    # Specifies the maximum accepted body size of a client request, as
    # indicated by the request header Content-Length. If the stated content
    # length is greater than this size, then the client receives the HTTP
    # error code 413. Set to 0 to disable.
    #client_max_body_size 0;
    client_max_body_size 100M;

    # Define the format of log messages.
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

    # Define the location of the log of access attempts to NGINX
    access_log /var/log/nginx/access.log  main;

    # Define the parameters to optimize the delivery of static content
    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;

    # Define the timeout value for keep-alive connections with the client
    #keepalive_timeout  7200;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    # Define the usage of the gzip compression algorithm to reduce the amount of data to transmit
    gzip  on;

    # Include additional parameters for virtual host(s)/server(s)
    include /etc/nginx/conf.d/*.conf;
}

uwsgi.ini

[uwsgi]
module = app
callable = app

uid = nginx
gid = nginx

socket = /tmp/uwsgi.sock
chown-socket = nginx:nginx
chmod-socket = 666

master = true
enable-threads = true
vacuum = true
die-on-term = true
need-app = true

cheaper = 50
#cheaper-step=2
#cheaper-algo=spare
#limit-post = 7516192768

harakiri = 120
max-requests = 5000
processes = 51

http-timeout=120
py-autoreload = 1

Please let me if I am missing something?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...