Sunday, 6 September 2020

Setting Nginx agar bisa Upload File di Moodle

Setelah moodle berhasil diakses secara global di internet, dimana saja kapan saja, muncul masalah tidak bisa mengupload tugas pada assignment moodle. Ini karena service nginx secara default membatasi file upload hanya 1MB. Apabila ukuran file lebih dari 1MB, tidak akan bisa diupload.


Agar bisa mengupload file lebih dari 1MB maka perlu dilakukan setting pada service nginx nya:

system administrators should also add client_max_body_size XXXm; to the "http" section of their nginx main configuration file

from: https://www.techrepublic.com/article/how-to-limit-file-upload-size-on-nginx-to-mitigate-dos-attack/

How to configure nginx.conf

The first thing we're going to do is change the upload limit to 100MB in the nginx.conf file. Open the file with the command:

sudo nano /etc/nginx/nginx.conf

Look for the http section and add the following line (Figure A):

client_max_body_size 100M;

Save and close the file.

Figure A

nginxuploada.jpg

Adding the configuration to NGINX config file.

Next, open the config file for your website. If you're using the default, you would open that file with the command:

sudo nano /etc/nginx/sites-available/default

In that file, look for the server section and add the same line as you did in the nginx.conf file (Figure B).

Figure B

nginxuploadb.jpg

Adding the configuration line in the server section of your site config file.

In that same file, locate the location section you've configured for site uploads and add the same line (Figure C).

Figure C

nginxuploadc.jpg

Adding the configuration line in the locations directive.

Of course, your uploads directive will probably be a bit more complex than the basic one I've illustrated, but you get the point.

Save and close the file.

Run the NGINX configuration test with the command:

sudo nginx -t

You shouldn't see any errors. Restart NGINX with the command:

sudo systemctl restart nginx

At this point, if anyone attempts to upload a file size larger than 100 MB, they'll receive a 413 error (Request Entity Too Large). Your NGINX server is now a tiny bit safer from DoS attacks, while still allowing your users to upload files. No, this isn't a be-all-end-all preventive measure for DoS attacks, but these days anything you can do to stave off the ne'er do wells is a step in the right direction.


Share:

0 comments:

Post a Comment