【问题标题】:How to increase upload image size on Nginx server?如何在 Nginx 服务器上增加上传图片的大小?
【发布时间】:2019-01-29 05:43:36
【问题描述】:

我在 Django 中开发了一个应用程序。我遇到了一些图像(大小:2MB)成功上传而一些图像(大小:4,5MB)在上传后生成错误的问题。经过研究,我发现这个问题是由于我的Nginx服务器文件上传大小造成的。

这是我的 nginx.conf 文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;


events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##



       
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
         # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";



        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
# 
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

我应该如何编辑这个文件以增加图片的上传大小大约 6MB。

当我关注这个问题时How to edit nginx.conf to increase file size upload

我收到以下错误:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-08-22 21:44:46 UTC; 19min ago
  Process: 10043 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 9254 (code=exited, status=0/SUCCESS)

Aug 22 21:44:46 ip-172-31-24-109 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 22 21:44:46 ip-172-31-24-109 nginx[10043]: nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size
Aug 22 21:44:46 ip-172-31-24-109 nginx[10043]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 22 21:44:46 ip-172-31-24-109 systemd[1]: nginx.service: Control process exited, code=exited status=1
Aug 22 21:44:46 ip-172-31-24-109 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Aug 22 21:44:46 ip-172-31-24-109 systemd[1]: nginx.service: Unit entered failed state.
Aug 22 21:44:46 ip-172-31-24-109 systemd[1]: nginx.service: Failed with result 'exit-code'.

所以请为我编辑文件。我知道可能只有一行代码。

【问题讨论】:

  • 通过谷歌搜索并首先检查 SO :) stackoverflow.com/questions/26717013/…
  • @NourChawich 我试过这个但得到以下错误:正在启动高性能 Web 服务器和反向代理服务器...:nginx:[emerg] 无法构建 server_names_hash,你应该增加 server_names_hash_bucket_size:nginx : 配置文件 /etc/nginx/nginx.conf 测试失败 systemd[1]: nginx.service: 控制进程退出,code=exited status=1 systemd[1]: 无法启动高性能web服务器和反向代理服务器. systemd[1]: nginx.service: 单元进入失败状态。 : nginx.service: 失败,结果为'exit-code'。

标签: nginx server nginx-config


【解决方案1】:

您的域名可能太长。 您是否尝试取消注释/更改此设置?

http {
    server_names_hash_bucket_size 64;
    ...
}

然后测试配置:

nginx -t

并重新加载 nginx:

systemctl status nginx

【讨论】:

    【解决方案2】:

    转到 nginx 文件:/etc/nginx/nginx.conf

    在 http 部分添加以下行。

    http { ......... ........ client_max_body_size maxSize(say 500M); }

    【讨论】:

      猜你喜欢
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      相关资源
      最近更新 更多