为了简单,采用了nginx+php配置文件服务器。
nginx的上传文件模块nginx_upload_module,源码安装的时候将该模块加上。
可以参考文章:
https://www.jianshu.com/p/ef9f75094a65
https://www.jianshu.com/p/7d2b0567521f
处理nginx的上传文件我使用的是php,所以需要安装php
sudo yum -y install nginx
参考文章:
https://www.cnblogs.com/huandada/p/10114722.html
php修改文件名rename函数老是返回false, 用print_r(get_last_error())发现是权限的问题。php是apache用户开启的,于是我先尝试将nginx文件目录的owner改为apache,
chown -R apache:apache /usr/local/nginx/html
结果还是权限不够,然后用ll命令看目录权限是755。
最后我将权限改为007, 居然可以了。为什么走的是other呢?搞不懂哦!!!
还遇到一个问题就是, php返回json的函数json_encode居然找不到。网上搜了一下,好像是php的json模块没有默认加入,需要手动安装。那就安装一下吧:
yum install php-json
对了php现在默认是sock的方式监听的,我改为了ip+端口的方式。配置文件在
etc/php-fpm.d/www.conf
再贴一下nginx的配置吧:
location /upload {
client_max_body_size 200m;
upload_pass /handle_upload.php;
upload_store /usr/local/nginx/html;
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;
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 "^.*$";
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}