2

I have developed an application in Django. I was stuck in the problem that some image(size:2MB)was uploaded successfully while some images(size:4,5MB) generate an error after upload. After research, I found that this issue is due to my Nginx server file upload size.

This is my nginx.conf file

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;
#       }
#}

How should I edit this file to increase the upload size of image approx 6MB.

When I follow this one question How to edit nginx.conf to increase file size upload

I got the following error:

● 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 please edit the file for me. I know there may be one line code only.

A.L
  • 10,259
  • 10
  • 67
  • 98
imsaiful
  • 1,556
  • 4
  • 26
  • 49
  • By Googling that and checking SO first :) https://stackoverflow.com/questions/26717013/how-to-edit-nginx-conf-to-increase-file-size-upload – Nour Wolf Aug 22 '18 at 22:02
  • Possible duplicate of [How to edit nginx.conf to increase file size upload](https://stackoverflow.com/questions/26717013/how-to-edit-nginx-conf-to-increase-file-size-upload) – Nour Wolf Aug 22 '18 at 22:03
  • @NourChawich I have tried this but got following error: Starting A high performance web server and a reverse proxy server... : nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size : nginx: configuration file /etc/nginx/nginx.conf test failed systemd[1]: nginx.service: Control process exited, code=exited status=1 systemd[1]: Failed to start A high performance web server and a reverse proxy server. systemd[1]: nginx.service: Unit entered failed state. : nginx.service: Failed with result 'exit-code'. – imsaiful Aug 22 '18 at 22:05

2 Answers2

2

It's possible your domain name is too long. Have you tried to uncomment/change this setting?

http {
    server_names_hash_bucket_size 64;
    ...
}

Then test config:

nginx -t

And reload nginx:

systemctl status nginx
0

Go to nginx file : /etc/nginx/nginx.conf

Add below line in http section.

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

KESHAV KUMAR
  • 140
  • 1
  • 7