【问题标题】:file upload not working | nginx | php-fpm | MAC | homebrew文件上传不工作| nginx | php-fpm |麦克 |自制
【发布时间】:2014-09-12 06:26:48
【问题描述】:

问题:我尝试将文件上传到 php 脚本,那里有 $_FILES(nginx 通常为空),$_REQUEST。 $_POST、$_GET、$_SERVER 不包含有关上传文件的任何内容

NGINX

nginx version: nginx/1.6.0
built by clang 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx-full/1.6.0 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx-full/1.6.0/bin/nginx --with-cc-opt=-I/usr/local/include --with-ld-opt=-L/usr/local/lib --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --add-module=/usr/local/share/upload-progress-nginx-module --add-module=/usr/local/share/upload-nginx-module

NGINX 配置

worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /usr/local/var/run/nginx.pid;

events {
    worker_connections  256;
}


http {
    upload_progress uploads 5m;

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

    server_names_hash_bucket_size 128;

    fastcgi_temp_file_write_size 10m;

    fastcgi_busy_buffers_size 1024;
    fastcgi_buffer_size 1024;
    fastcgi_buffers 16 1024;
    client_max_body_size 100m;

    proxy_buffer_size   1024k;
    proxy_buffers   4 1024k;
    proxy_busy_buffers_size   1024k;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;

    access_log  /var/log/nginx/access.log;
    port_in_redirect off;
    sendfile        on;
    keepalive_timeout  65;





    include /usr/local/etc/nginx/conf.d/*.conf;
}

NGINX 虚拟主机 服务器 { 根 /var/www/website/public;

    location /upload {

        # Pass altered request body to this location
        upload_pass @page;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
        upload_store /var/www/website/tmp 1;

        # Allow uploaded files to be read only by user
        upload_store_access user:rw;

        # Set specified fields in request body
        upload_set_form_field $upload_field_name.name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.path "$upload_tmp_path";

        # Inform backend about hash and size of a file
        upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
        upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;

        upload_pass_form_field "(.*)";

        ## Track uploads for this location on the zone defined
        ## above with a 60 seconds timeout.
        track_uploads uploads 60s;
    }

    location / {
        rewrite ^(.*)\.[0-9]+\.(css|js|jpg|jpeg|png|gif|ico)$ $1.$2 break;

        rewrite ^/?(media)/(.+)\.(ogg|ogv|mp3|mp4|ico|css|js|gif|jpe?g|png|swf|pdf) /file.php?name=$1/$2.$3&ext=$3&$query_string last;

        try_files $uri @page;
    }

    location @page {
        rewrite "^(?:/?(?:([\w\-_]+)/?)?(?:([\w\-_]*)/?)?)?" /index.php?page=$1&item=$2 last;
    }

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param APP_ENV development;

        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;

        include       fastcgi_params;
    }
}

【问题讨论】:

    标签: php macos nginx


    【解决方案1】:

    (以防万一有人也试图让文件上传与 nginx 一起工作......)

    经过多次尝试和研究...我将安装 apache...

    自 nginx 1.3 以来唯一真正有效的上传模块支持停止,没有真正的替代品(保存到文件的主体也不起作用,文件损坏,没有文件名,其他 post/form 参数丢失)

    我发现的唯一真正有帮助的文章是:https://coderwall.com/p/swgfvw

    它非常令人失望,apache 有它,我不知道可能从永远开始多久,它只是工作......不需要任何配置......只是 bam..

    【讨论】:

      【解决方案2】:

      client_body_buffer_size 10M 添加到您的 nginx.conf。

      这对我有用。

      作为参考,我在这里找到了它: http://support.scalr.net/discussions/problems/2045-new-nginx-500-error-on-file-upload-for-files-over-1-mb-in-size-only-on-http

      【讨论】:

        猜你喜欢
        • 2014-08-17
        • 1970-01-01
        • 2014-08-04
        • 2021-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多