gpt4 book ai didi

django - 413请求实体太大nginx django

转载 作者:行者123 更新时间:2023-12-04 02:20:44 27 4
gpt4 key购买 nike

我正在制作一个练习 Web 服务(客户端的艺术书显示网站)客户端可以将艺术书图像上传到服务器。

但是当客户端上传太多图片时出现以下错误

413 Request Entity Too Large

我尝试添加 client_max_body_size 100M;在 nginx.conf 中
#user  nobody;
#Defines which Linux system user will own and run the Nginx server

worker_processes 1;

#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.

#pid logs/nginx.pid;
#nginx will write its master process ID(PID).

events {
worker_connections 1024;
}


http {
include mime.types;

default_type application/octet-stream;

#access_log logs/access.log main;

sendfile on;

server {
listen 80;

server_name xxxx.net;
client_max_body_size 100M;
keepalive_timeout 5;

return 301 https://$server_name$request_uri;

}

# HTTPS server
#
server {
listen 443 default_server ssl;
server_name xxx.net;

ssl_certificate /etc/letsencrypt/live/xxxx.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxxx.net/privkey.pem;

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


location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;

proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
}
}
}

并尝试:
sudo service nginx restart
sudo service nginx reload

并重试
runserver 

但仍然得到
413 Request Entity Too Large

有人可以帮忙吗?

最佳答案

您已经解决了 HTTP 服务器上的问题,但是您的 HTTP 服务器设置为 301 重定向到您的 HTTPS 服务器...您的 HTTPS 服务器没有 client_max_body_size已配置,因此默认为 1M 并导致此 413(请求实体太大)错误。

要解决此问题,您只需添加 client_max_body_size两者 HTTP 服务器块 HTTPS 服务器块,如下例所示:

http {
...
######################
# HTTP server
######################
server {
...
listen 80;
server_name xxxx.net;
client_max_body_size 100M;
...
}

######################
# HTTPS server
######################
server {
...
listen 443 default_server ssl;
server_name xxxx.net;
client_max_body_size 100M;
...
}
}

更多信息 client_max_body_size这里: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

Syntax: client_max_body_size size;

Default: client_max_body_size 1m;

Context: http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.



在此处阅读有关配置 HTTPS 服务器的更多信息: http://nginx.org/en/docs/http/configuring_https_servers.html

关于django - 413请求实体太大nginx django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36994828/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com