文件上传无效| nginx | php-fpm | MAC |自制

时间:2014-07-21 16:45:23

标签: php macos nginx

问题:我尝试将文件上传到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 CONFIG

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 VHOST     服务器{         root / 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;
    }
}

2 个答案:

答案 0 :(得分:0)

(以防万一有人也尝试使用nginx使文件上载工作...)

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

唯一真正有效的上传模块支持已停止,因为nginx 1.3没有真正的替代方案(保存体到文件也不起作用,文件损坏,没有文件名,缺少其他帖子/表单参数)

我找到的唯一真正的帮助文章是:https://coderwall.com/p/swgfvw

它非常令人失望,apache有它我不知道多久可能永远,它只是工作......没有配置需要什么......只是bam ..

答案 1 :(得分:-1)

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