使用NGINX,Laravel Forge通过AJAX上传PHP vimeo上的502 Bad Gateway

时间:2017-04-24 22:06:47

标签: php laravel ubuntu nginx laravel-forge

我正在使用Laravel(5.4)Forge用于从S3上传Vimeo和Youtube视频的网络应用。在过去,在迁移到Forge之前,这个脚本工作正常,并且今天仍可以正常使用较小的文件。

现在我正在尝试上传更大的文件(~1gb),我在php上传脚本超过1分钟后收到502 Bad Gateway。应用程序的其余部分运行正常。

具体来说,这是错误:

2017/04/24 20:36:48 [error] 2111#2111: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: X.X.X.X.X, server: myserver.com, request: "POST /recordings/vimeo/upload HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "myserver.com", referrer: "http://myserver.com/recordings"

我试过了:

  • 在nginx配置中添加/编辑fastcgi指令
  • 在php中提升output_buffering
  • 下添加proxy_和client_max_body项目

这是我的NGINX配置:

include forge-conf/myserver.com/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name .myserver.com;
    root /home/forge/myserver.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'hidden for SO';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    include forge-conf/myserver.com/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/myserver.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_read_timeout 3600;
        fastcgi_buffers 8 512k;
        fastcgi_buffer_size 512k;

        include fastcgi_params;


        client_max_body_size 128M;
        proxy_buffer_size 256k; 
        proxy_buffers 4 512k;
        proxy_busy_buffers_size 512k;

    }

    location ~ /\.ht {
        deny all;
    }
}

include forge-conf/myserver.com/after/*;

我错过了什么?我似乎无法弄清楚这一点。提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我遇到了同样的 502 问题,经过一些调试后发现我在 nginx 中遇到了限制,而在 PHP 中没有问题。

将以下内容添加到我的网站配置中,现在似乎可以正常工作了:

server{

fastcgi_temp_file_write_size 10m;
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;

#...our rest of config
}

通常你可以在里面找到 nginx 配置文件

/etc/nginx/sites-available/default/etc/nginx/sites-available/your_domain.com