nginx server error: 413 Request Entity Too Large

The nginx webserver has a max. body size limit of 1 MB for requests as default. This might be too low for file uploads in scripts and you will see the following error message when you try to upload a file:

413 Request Entity Too Large

The configuration variable for this option is “client_max_body_size” and it can be set in the http, server and location sections of the nginx configuration file. To set the Limit globally to 25 MB, edit the nginx.conf file and add:

client_max_body_size 20M;

in the http section.

Example for Ubuntu Linux:

user www-data;
worker_processes 4;
pid /var/run/;

events {
        worker_connections 768;
        # multi_accept on;

http {
        geoip_country  /etc/nginx/geoip/GeoIP.dat; # the country IP database
        geoip_city     /etc/nginx/geoip/GeoLiteCity.dat; # the city IP database
        # Basic Settings

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        client_max_body_size 20M;

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

        # Logging Settings

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

        # Gzip Settings

        gzip on;
        gzip_disable "msie6";

        # Virtual Host Configs

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

Nginx and php upload_max_filesize : other setups

Nginx and PHP-FPM Installation

Jump to: navigation, search

Nginx Installation in ProcessMaker has been included under an experimental section, since this installation has not being tested by QA Department yet, so this is not officialy supported by ProcessMaker.

Follow these instructions to install ProcessMaker 2.0 on top of a LNMP (Linux, Nginx, MySQL, PHP-FPM) stack in Ubuntu (Maverick Meerkat) 10.10 and later.


nginx (pronounced “Engine X” is a lightweight, high-performance server. It’s used among websites with high traffic to improve page responses and serving external files (CSS, JS, images) faster and with less memory footprint than the Apache webserver.


PHP-FastCGI Process Manager is a set of patches for PHP to work with the FastCGI process manager, turning PHP-FPM into a service rather than loading all of its libraries everytime a PHP request it’s made. PHP-FPM it’s used in conjunction with Nginx to drastically improve performance and to deal with many concurrent users.

Install Nginx, PHP-FPM and MySQL

Please note: You need to have the Apache webserver uninstalled or stopped to install Nginx

Open a shell by going to Applications > Accessories > Terminal. Enter the following:

sudo apt-get install nginx mysql-server mysql-client php5-fpm php5-mysql php5-curl php5-cli php5-common php5-geoip php5-mcrypt php5-memcache php-xml-serializer php-xml-parser php-soap php5-ldap php5-gd

When apt-get installs MySQL, a dialog box will appear asking for a new root password for MySQL.


Enter a password and select the option OK. If everything worked, you should be able to go to http://localhost

Install ProcessMaker

Follow the instructions at

Configure MySQL

Follow the instructions at

Configure PHP-FPM

Type this in your terminal:

sudo vi /etc/nginx/nginx.conf

locate the worker_processes line and change it to this:

worker_processes 5;

save the changes and close the file.

We also need to edit the php.ini file:

sudo vi /etc/php5/fpm/php.ini

Each ProcessMaker session needs a minimum of 80MB RAM to run properly, so set the memory_limit to 80M or greater:

memory_limit = 80M

In order to upload Input Documents, upgrade ProcessMaker and add plugins and languages, file_uploads need to be enabled:

file_uploads = On

ProcessMaker needs to use PHP’s short opening tags:

short_open_tag = On

If planning on uploading large Input Documents while running processes, the post_max_size and upload_max_filesize should be increased to more than the default 2MB. For instance, if planning on uploading files as large as 16MB, then:

post_max_size = 16M 
upload_max_filesize = 16M

Now we restart the PHP-FPM service:

sudo /etc/init.d/php5-fpm stop
sudo /etc/init.d/php5-fpm start

Configure Nginx

The last step is to configure Nginx. We’ll follow the same structure found on but using nginx directives:

sudo vi /etc/nginx/sites-available/pmos

Copy and paste the following:

server {
listen your_ip_address:80;
server_name _;
root /opt/processmaker/workflow/public_html;
index index.html;
rewrite ^/.*/(.*)$ /sysGeneric.php last;
# Every PHP script must be routed to PHP-FPM
location ~ \.php$ {
     if(!-f $request_filename) { return 404; }
     fastcgi_index    index.php;
     fastcgi_param    SCRIPT_FILENAME   /opt/processmaker/workflow/public_html$fastcgi_script_name;
     include fastcgi_params;

Replace your_ip_address with the IP number or domain name of the server running ProcessMaker. If only planning on running and accessing ProcessMaker on your local machine, then use the IP address “”. If using ProcessMaker on a machine whose IP address might change (such as a machine whose IP address is assigned with DHCP), then just use “80”.

If your DNS or /etc/hosts has a defined domain for ProcessMaker, then use that domain instead of the underscore “_” on the server_name line. Otherwise, just leave it as it is.

Now we need to enable the processmaker site:

sudo ln -s /etc/nginx/sites-available/pmos /etc/nginx/sites-enabled/pmos

Restart the server

sudo /etc/init.d/nginx restart

Setting Up ProcessMaker

Follow the instructions at

SSL on Nginx

Nginx has an SSL module which can be used with ProcessMaker. Read more at

Install phpMyAdmin on a LEMP server

Step One—Install phpMyAdmin

Start off by downloading the program from apt-get.

sudo apt-get install phpmyadmin

During the installation, phpmyadmin will ask you if you want to configure the database with dbconfig. Go ahead and choose yes.

Input MySQL’s database password when prompted and click ok.

When phpmyadmin prompts you to choose a server (either apache or lighttpd) hit tab, and select neither one.

Step Two—Configure phpMyAdmin

You now have phpMyAdmin installed on your server. In order to access it, you need to take one more step.

Create a symbolic link between phpMyAdmin and your site’s directory. If you were using the previous tutorial, it may be still located in the nginx default directory, otherwise link it with the appropriate place:

sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www

Restart nginx:

sudo service nginx restart

Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support (LEMP) On Ubuntu 12.04 LTS

Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how you can install Nginx on an Ubuntu 12.04 LTS server with PHP5 support (through PHP-FPM) and MySQL support (LEMP = Linux + nginx (pronounced “engine x”) + MySQL + PHP).

I do not issue any guarantee that this will work for you!

1 Preliminary Note

In this tutorial I use the hostname with the IP address These settings might differ for you, so you have to replace them where appropriate.

I’m running all the steps in this tutorial with root privileges, so make sure you’re logged in as root:

sudo su

2 Installing MySQL 5

In order to install MySQL, we run

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user – this password is valid for the user root@localhost as well as, so we don’t have to specify a MySQL root password manually later on:

New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword

3 Installing Nginx

Nginx is available as a package for Ubuntu 12.04 which we can install as follows:

apt-get install nginx

Start nginx afterwards:

/etc/init.d/nginx start

Type in your web server’s IP address or hostname into a browser (e.g., and you should see the following page:

The default nginx document root on Ubuntu 12.04 is /usr/share/nginx/www.

4 Installing PHP5

We can make PHP5 work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites) which we install as follows:

apt-get install php5-fpm

PHP-FPM is a daemon process (with the init script /etc/init.d/php5-fpm) that runs a FastCGI server on port 9000.

5 Configuring nginx

The nginx configuration is in /etc/nginx/nginx.conf which we open now:

vi /etc/nginx/nginx.conf

The configuration is easy to understand (you can learn more about it here: and here:

First (this is optional) adjust the number of worker processes and set the keepalive_timeout to a reasonable value:

worker_processes  4;
    keepalive_timeout   2;

The virtual hosts are defined in server {} containers. The default vhost is defined in the file /etc/nginx/sites-available/default – let’s modify it as follows:

vi /etc/nginx/sites-available/default

server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                deny all;

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index index.php;
                include fastcgi_params;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        location ~ /\.ht {
                deny all;

Uncomment both listen lines to make nginx listen on port 80 IPv4 and IPv6.

server_name _; makes this a default catchall vhost (of course, you can as well specify a hostname here like

I’ve added index.php to the index line. root /usr/share/nginx/www; means that the document root is the directory /usr/share/nginx/www.

The important part for PHP is the location ~ \.php$ {} stanza. Uncomment it to enable it. Please note that I’ve added the line try_files $uri =404; to prevent zero-day exploits (see and,88845,page=3). Alternatively, if you don’t want to use the try_files $uri =404; line, you can set cgi.fix_pathinfo = 0; in /etc/php5/fpm/php.ini (don’t forget to reload PHP-FPM afterwards).

Now save the file and reload nginx:

/etc/init.d/nginx reload

Now create the following PHP file in the document root /usr/share/nginx/www:

vi /usr/share/nginx/www/info.php


Now we call that file in a browser (e.g.

As you see, PHP5 is working, and it’s working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.

6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Xcache is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It’s similar to other PHP opcode cachers, such as eAccelerator and APC. It is strongly recommended to have one of these installed to speed up your PHP page.

Xcache can be installed as follows:

apt-get install php5-xcache

Now reload PHP-FPM:

/etc/init.d/php5-fpm reload

Now reload in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

7 Making PHP-FPM Use A Unix Socket

By default PHP-FPM is listening on port 9000 on It is also possible to make PHP-FPM use a Unix socket which avoids the TCP overhead. To do this, open /etc/php5/fpm/pool.d/www.conf…

vi /etc/php5/fpm/pool.d/www.conf

… and make the listen line look as follows:

;listen =
listen = /tmp/php5-fpm.sock

Then reload PHP-FPM:

/etc/init.d/php5-fpm reload

Next go through your nginx configuration and all your vhosts and change the line fastcgi_pass; to fastcgi_pass unix:/tmp/php5-fpm.sock;, e.g. like this:

vi /etc/nginx/sites-available/default

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/tmp/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

Finally reload nginx:

/etc/init.d/nginx reload