Author Topic: "File upload failed." on NGINX platform  (Read 6780 times)

Offline one1page

  • Newbie
  • *
  • Posts: 3
"File upload failed." on NGINX platform
« on: April 19, 2015, 03:42:18 AM »
Hi everyone,

Im a newbie here on server-hosting but i successfully setup ubuntu 14.04 with LEMP(Linux,Engine-X/Nginx,Mysql,PHP) platform. Been few months already since my server is running but recently i receive an issue from our company email user that they have file attachment problem on roundcube webmail. When i checked, there's really "File upload failed." whenever i try to upload/attached more than 2mb file. I already changed the following from php ini:

upload_max_filesize   10M
post_max_size         25M
memory_limit          128M

At first im even thinking(i know its a bit stupid idea) that maybe .htaccess is working on my nginx server so i also tried to change those php values in the .htaccess file on roundcube root folder but nothing happened.

I cannot get any useful details from php log files and even in nginx logs.

I tested the file limit actually is working ok because whenever i try to upload more than 10mb file i get different error which is "The uploaded file exceeds the maximum size of 10 MB." so i suspect i have a correct configuration on my server"?" And besides, uploading more than 2mb but less than 10mb file/s is no problem on other webmails running on the server such as squirrelmail.

Anybody here have any idea what i missed out on my roundcube configuration? Roundcube is awesome and i want to use it as our main webmail on the server.

Thanks in advance and more power!
-Gerard
« Last Edit: April 19, 2015, 04:28:33 AM by one1page »

Offline one1page

  • Newbie
  • *
  • Posts: 3
UPDATE: "File upload failed." on NGINX platform
« Reply #1 on: April 19, 2015, 06:41:41 AM »
UPDATE:
Look like this is a roundcube bug.

I tested the online demo provided by MyRoundcube Dev Team/ on https://s2.myroundcube.com/ and I uploaded more than 2mb files, i get same error: "File upload failed.".
The online demo shows that the maximum file size allowed is up to 5mb and the file I uploaded is only 2.4mb.

If anyone encountered same issue and manage to solve it please let me know.

Thanks and Regards to all,
-Gerard

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,502
    • http://SKaero.com/
Re: "File upload failed." on NGINX platform
« Reply #2 on: April 19, 2015, 04:21:08 PM »
Its not a Roundcube bug its a configuration problem. First create a php file in the Roundcube folder with the following to verify the php.ini changes have taken effect:
Code: [Select]
<?php phpinfo();Second make sure the temp directory is writable, and third make sure you have client_max_body_size in your Nginx set higher than 2mb,

Offline one1page

  • Newbie
  • *
  • Posts: 3
Re: "File upload failed." on NGINX platform
« Reply #3 on: April 22, 2015, 10:12:39 PM »
Its not a Roundcube bug its a configuration problem. First create a php file in the Roundcube folder with the following to verify the php.ini changes have taken effect:
Code: [Select]
<?php phpinfo();Second make sure the temp directory is writable, and third make sure you have client_max_body_size in your Nginx set higher than 2mb,

Thanks SKaero!!

client_max_body_size on nginx conf solved the problem.

For those who encountered same issue, I managed to solve it by adding this in nginx.conf:

client_max_body_size 25M;

my max_post_size is 25M that is why i make the client_max_body_size 25M as well.

Thanks Everyone!!!!

-Gerard

Offline igame

  • Newbie
  • *
  • Posts: 4
Re: "File upload failed." on NGINX platform
« Reply #4 on: November 21, 2015, 01:11:12 AM »
Even if this post is so old, I can not help replying it because google push it to me at the first sight.
Hoppingly this reply could help the who is still fighting with this out a little bit.

I run my roundcubemail under KVM,  typically LMNR(Linux+MySql+Nginx+Roundcubemail).
Here is a brief of my environment:
Host: HP GL380 G6 X5560x2, 64G Mem, CentOS 7.1, KVM
Guest: vCPUx2, 4G Mem, CentOS 7.1
Host and Guest have the minimal installation of CentOS. Guest also disabled selinux and firewall.

To make a successfully uploading, probably we have to do the following things:

1. SMTP service(postfix): message_size_limt
By default, postfix has a limit of 10M for message(reference:http://www.postfix.org/postconf.5.html#message_size_limit). Actually, it's 9.7MB if one MB has 1024*1024 bytes. It decides the total of attachments you can send. But you can NOT send message as same as exact this value, it is 1.5 times of the total you can send by my experience. So the max size of your all attachments should be message_size_limt / 1.5. For example, 128M means you can send a mail with almost 85M attachments total. Also you will be noticed by the reference above that if the destination mail server can not accept attachments as same as the size of you , you will still experience failure. However, if you just test in local machine, the value will help you out "SMTP Service: message exceeds size limit" error.
Change or add following line in /etc/postfix/main.cf:
Code: [Select]
# 128M max, so we can send 85M attachments for total.
message_size_limit = 134217728

2. Nginx
Config /etc/nginx/nginx.conf, change or add client_max_body_size like this:
Code: [Select]
client_max_body_size 128m;

3. PHP
Change the two values according to your needs, they decide how big file you can upload(but not the max size your mail server can accept).
Code: [Select]
post_max_size = 128M
upload_max_filesize = 128M
# Having plenty of memory
memory_limit = 512M

4. Roundcubemail
Making roundcubemail accept fatty file needs efforts:

1) program/steps/mail/attachments.inc
Code: [Select]
99     if (!$err && $attachment['status'] && !$attachment['abort']) {
The checking of $attachment['status'] is always false so that your uploading won't go any further.
You can just omit it(of course, you take your own rick):
Code: [Select]
99     if (!$err && !$attachment['abort']) {

2) program/lib/Roundcube/rcube_cache.php
Code: [Select]
48      private $max_packet = -1;
...
...
613    private function max_packet_size()
614     {
615         if ($this->max_packet < 0) {
616             $this->max_packet = 2097152; // default/max is 2 MB   <---- This is max size of one attachment, you can upload many attachments but each must have a size less than 2MB.
My resolution is simple, and rude:
Code: [Select]
48    private $max_packet = 134217728; // 128M

3) program/lib/Roundcube/rcube_message.php
Code: [Select]
66    const BODY_MAX_SIZE = 1048576; // 1MB
It may cause the famous 1046576 error, so change it accordingly:
Code: [Select]
66    const BODY_MAX_SIZE = 134217728; // 128MB


Before all, make sure the roundcubemail can read/write the uploading directory.
After all, restart postfix, php-fpm and nginx, open browser, upload and then prey.
Good luck! ;D
« Last Edit: November 21, 2015, 01:56:34 AM by igame »

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,502
    • http://SKaero.com/
Re: "File upload failed." on NGINX platform
« Reply #5 on: November 21, 2015, 03:36:45 AM »
Thanks for posting a solution!

Offline igame

  • Newbie
  • *
  • Posts: 4
Re: "File upload failed." on NGINX platform
« Reply #6 on: November 23, 2015, 01:44:14 PM »
My pleasure.  ;D