Nginx Error – 413 Request Entity Too Large Fix

If you’re getting 413 Request Entity Too Large errors trying to upload files to your webserver, you need to increase the client body size limit in your nginx.conf configuration file.

Add ‘client_max_body_size xxM’ inside the server section, where xx is the size (in MB) that you want to allow for files upload to your webserver.

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.

To edit your nginx configuration, in your terminal type the following:

sudo nano /etc/nginx/nginx.conf
or
sudo nano /usr/local/nginx/conf/nginx.conf
and set the
# set client body size to 2M #
client_max_body_size 2M;

as per the example below:

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
client_max_body_size 2M;
listen 80;
server_name localhost;

# Main location
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
}

WordPress theme upload error “PCLZIP_ERR_BAD_FORMAT (-10)”

While trying to install a wordpress theme that was packaged as an .rar archive I got the following error:

The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature

This is because I’m trying to unpack a .rar archive and the server doesn’t have rar archive support installed, however you can get around this issue quite easily.

All you need to do is unpack the .rar archive and re-pack it as a .zip archive and re-try the upload. Everything will work as expected after that.

Install / upgrade to latest Nginx without compiling from source

Nginx server update without compiling

You can install the Nginx package from the regular Ubuntu/Debian repositories, but the versions there are generally lagging behind the current stable/development releases.

In this post, I’ll show you how to install/upgrade the latest stable or development version through Ubuntu’s package manager without having to compile Nginx from source!

1. Ubuntu guide:

1.1 Switch to root:

 sudo -i 

1.2 Update your local list of packages:

 apt-get update

1.3 Install the python-software-properties package:

 apt-get install python-software-properties

1.4 Add the Nginx Launchpad Repository:

1.4.1 Option 1 (the easy way using add-apt-repository):

 add-apt-repository ppa:nginx/development

or if you want the latest stable release use

 add-apt-repository ppa:nginx/stable

1.4.2 Option 2:

1.4.2.1 Add the repository to your sources.list using the following command:

 echo "deb http://ppa.launchpad.net/nginx/development/ubuntu $(lsb_release -cs) main" >> /etc/apt/sources.list

or if you want the latest stable release use

 echo "deb http://ppa.launchpad.net/nginx/release/ubuntu $(lsb_release -cs) main" >> /etc/apt/sources.list

Note: lsb_release -cs will grab your current ubuntu install codename

1.4.2.2 get and add the repository public key:

 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C

1.5 Update your local list of packages again:

 sudo apt-get update

1.6 Check current Nginx version:

 nginx -v
nginx version: nginx/1.2.4

1.7 Now, you can install (actually upgrade) the latest version of Nginx just like any other package (we must use forced install otherwise it will fail):

1.7.1 To upgrade:

 apt-get upgrade nginx -f

When asked what to do with the Nginx configuration file /etc/nginx/nginx.conf select
N in orer to keep your current Nginx configuration file.

1.7.2 To install (if not performing an upgrade):

 apt-get install nginx -f

1.8 When the install is done, check your current version of nginx:

 nginx -v

It should read: nginx version: nginx/1.3.8

1.9 Now just to be on the safe side and make sure everything is ok, restart the nginx service followed by a reload of the configuration to make sure statuses are OK:

 service nginx restart
service nginx reload

You are done!
Things on Debian are a little bit different since we cannot use the add-apt-repository ppa:nginx/development command since add-apt-repository is a Ubuntu specific utility that comes along in the python-software-properties packages, however since nginx isn’t all that different for Debian from Ubuntu, we can use Ubuntu development repositories to install the nginx development version bu manually modifying the sources.list file.

2.1 Switch to root:

 sudo -i

2.2 Open for edit your sources.list repositories:

 nano /etc/apt/sources.list

2.3 And add the following line at the bottom of the file:

 deb http://ppa.launchpad.net/nginx/development/ubuntu lucid main

Note: for latest stable version use

 deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main

or

 deb http://ppa.launchpad.net/nginx/development/ubuntu quantal main

Note: for latest stable version use

 deb http://ppa.launchpad.net/nginx/stable/ubuntu quantal main

Note: check out ubuntu develoment codenames here if you want to use others: https://wiki.ubuntu.com/DevelopmentCodeNames if you’d like to use a different ubuntu version repository.

2.3 Next, download and add the repository private key:

  apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C

2.4 Update your local list of packages:

 apt-get update

2.5 Check current Nginx version:

 nginx -v
nginx version: nginx/1.2.8

2.6 Perform the Nginx webserver upgrade (use forced version):

2.6.1 To upgrade:

 apt-get upgrade nginx -f

When asked what to do with the Nginx configuration file /etc/nginx/nginx.conf select
N in order to keep your current Nginx configuration file.

2.6.2 To install (if not performing an upgrade):

 apt-get install nginx -f

2.7 When the install is done, check your current version of Nginx:

 nginx -v
It should read: nginx version: nginx/1.3.8

2.8 Now just to be on the safe side and make sure everything is ok, restart the Nginx service followed by a reload of the configuration to make sure statuses are OK:

 service nginx restart
service nginx reload

You are done!

3. Now to see the status of your current services type in the following:

 service --status-all

Guide tested on:

Distributor ID: Ubuntu
Description:    Ubuntu 12.10
Release:        12.10
Codename:       quantal

  AND

Distributor ID: Debian
Description:    Debian GNU/Linux 6.0.6 (squeeze)
Release:        6.0.6
Codename:       squeeze

Post inspired from Clay Richardson.