简体   繁体   English

同时文件上传返回403禁止使用nginx和php-fpm

[英]Simultaneous file uploads return 403 forbidden with nginx, and php-fpm

I have an application that allows simultaneous file uploads via drag and drop. 我有一个应用程序,允许通过拖放同时上传文件。 This application currently: 此应用目前:

  • Has 3 versions of it's instance local, staging, production. 它有3个版本的实例本地,登台,生产。
  • Runs php 5.6 on nginx w/ php-fpm nginx w / php-fpm上运行php 5.6
  • Built on the CakePhp2. 建立在CakePhp2上。

Here is the problem I'm having: 这是我遇到的问题:

  1. I upload 1 image, 1 succeeds, everything works. 我上传1张图片,1张成功,一切正常。
  2. I upload 2 images, 1 succeeds, 403 is returned for second upload request. 我上传2张图片,1张成功,403返回第二次上传请求。
  3. I upload 3+ images, 1 succeeds, 403 is returned for all other requests, user is logged out of application (session expires) 我上传3个以上的图像,1个成功,所有其他请求返回403,用户退出应用程序(会话到期)

This happens anytime there are multiple concurrent posts. 只要有多个并发帖子,就会发生这种情况。 They do not have to be file uploads. 它们不必是文件上传。

This feature works on all servers except the staging server. 此功能适用于除登台服务器之外的所有服务器。 Local dev machines and the production box do not have this issue. 本地开发机器和生产盒没有这个问题。

Files are uploaded by drag and drop onto the page. 通过拖放到页面上传文件。 Each file is uploaded via ajax in a separate request. 每个文件都通过ajax在单独的请求中上传。

Size doesn't matter small images fail as well as larger images. 尺寸无关紧要小图像失败以及更大的图像。

I'm looking for mis-matching config parameters between environments but the difference is not obvious yet. 我正在寻找环境之间不匹配的配置参数,但差别尚不明显。 Any ideas what I should check? 我应该检查什么想法?

My nginx site config: 我的nginx网站配置:

server {
   listen       *:443 ssl;

   server_name  stagingsite.com ;

   ssl on;
   ssl_certificate           /site.crt;
   ssl_certificate_key       /site.key;
   ssl_session_cache         shared:SSL:10m;
   ssl_session_timeout       5m;
   ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers               "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-    SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384: ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-   SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-   CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:    AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!  MD5:!PSK:!RC4";
 ssl_prefer_server_ciphers on;
 client_max_body_size 256m;
 index  index.html index.htm index.php;

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

 root /var/www/site/webroot;

 location / {
    root  /site/webroot;
    try_files $uri $uri/ /index.php$is_args$args;
    autoindex off;     
    index  index.html index.htm index.php;
 }

 location ~ \.php$ {
 set $path_info $fastcgi_path_info;
 fastcgi_index index.php;
 fastcgi_split_path_info ^(.+\.php)(/.*)$;
 try_files $uri $uri/ /index.php$is_args$args;
 include /etc/nginx/fastcgi_params;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_param SCRIPT_FILENAME $request_filename;
   }

   sendfile off;
} 

I discovered the answer to my question. 我发现了我的问题的答案。 The problem lived within CakePhp2 's session configuration. 问题存在于CakePhp2的会话配置中。 The auto-regenerate option was set to true cause the application to generate a new session id for each request. auto-regenerate选项设置为true,导致应用程序为每个请求生成新的会话ID。 After the second request came in, it didn't know the new session id. 第二个请求进入后,它不知道新的会话ID。 By the time the third request came in the session ID was lost all together. 到第三个请求进入会话时,ID一起丢失了。

Resources that led to discover of solution are here: 导致发现解决方案的资源在这里:

How to resolve "ajax 403 error forbidden in CAKEPHP 2.x" 如何解决“CAKEPHP 2.x中禁止的ajax 403错误”

CakePHP 403 on AJAX request 关于AJAX请求的CakePHP 403

I hope this question helps the next guy that comes across something like this. 我希望这个问题有助于下一个遇到类似问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM