Nginx: 413 – Request Entity Too Large Error at Ubuntu and Solution

Nginx: 413 – Request Entity Too Large Error and Solution

Nginx configuration

To fix this issue edit your nginx.conf. Open the Terminal or login to the remote server using ssh client. Type the following command to edit your nginx.conf using a text editor such as vi or joe or nano:
# vi /etc/nginx/nginx.conf

Use nano text editor:
$ sudo nano /etc/nginx/nginx.conf

Must be run as root:
# vi /usr/local/nginx/conf/nginx.conf

Add the following line to http or server or location context to increase the size limit in nginx.conf, enter:

# set client body size to 2M #
client_max_body_size 2M;

The client_max_body_size directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error “Request Entity Too Large” (413).
Save and close the file. Reload the nginx webserver, enter:
# /usr/local/nginx/sbin/nginx -s reload

Use nginx itself to reload it:
# /sbin/nginx -s reload

For RHEL/CentOS/Debian/Ubuntu Linux, try:
# service nginx reload

If you are using systemd based system run:
$ sudo systemctl reload nginx.service

PHP configuration (optional)

Your php installation also put limits on upload file size. Edit php.ini and set the following directives

;This sets the maximum amount of memory in bytes that a script is allowed to allocate
memory_limit = 32M

;The maximum size of an uploaded file.
upload_max_filesize = 2M

;Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 3M
If you are using PHP-FPM, restart it as follows:
$ sudo systemctl restart php-fpm
## OR ##
$ sudo systemctl restart php7.0-fpm.service
## OR ##
$ sudo /usr/local/etc/rc.d/php-fpm restart

Save and close the file. Make sure you reload/restart back-end apache or nginx web server as per your setup.

Advertisements

Enable Remote Connections Mysql Ubuntu

To expose MySQL to anything other than localhost you will have to have the following line

For mysql version 5.6 and below

uncommented in /etc/mysql/my.cnf and assigned to your computers IP address and not loopback

For mysql version 5.7 and above

uncommented in /etc/mysql/mysql.conf.d/mysqld.cnf and assigned to your computers IP address and not loopback

#Replace xxx with your IP Address
bind-address = xxx.xxx.xxx.xxx
Or add a bind-address = 0.0.0.0 if you don’t want to specify the IP

Then stop and restart MySQL with the new my.cnf entry. Once running go to the terminal and enter the following command.

lsof -i -P | grep :3306
That should come back something like this with your actual IP in the xxx’s

mysqld 1046 mysql 10u IPv4 5203 0t0 TCP xxx.xxx.xxx.xxx:3306 (LISTEN)
If the above statement returns correctly you will then be able to accept remote users. However for a remote user to connect with the correct priveleges you need to have that user created in both the localhost and ‘%’ as in.

CREATE USER ‘myuser’@’localhost’ IDENTIFIED BY ‘mypass’;
CREATE USER ‘myuser’@’%’ IDENTIFIED BY ‘mypass’;
then,

GRANT ALL ON *.* TO ‘myuser’@’localhost’;
GRANT ALL ON *.* TO ‘myuser’@’%’;
and finally,

FLUSH PRIVILEGES;
EXIT;

Restart Mysql service and test again with new user to mysql from remote access.