简体   繁体   English

使用 cURL 上传文件到 Nginx

[英]Upload file to Nginx with cURL

All,全部,

I'm trying to upload a local file to my remote Nginx server via cURL.我正在尝试通过 cURL 将本地文件上传到我的远程 Nginx 服务器。 I have built Nginx from source with the upload module and the DAV module.我已经使用上传模块和 DAV 模块从源代码构建了 Nginx。 At the bottom of the Nginx page, there is an example form to upload a file.在 Nginx 页面的底部,有一个用于上传文件的示例表单。 I'm not sure how I would implement the form, and (several) Google searches have returned little helpful information about uploading directly to Nginx via cURL.我不确定我将如何实现该表单,并且(几次)Google 搜索返回了关于通过 cURL 直接上传到 Nginx 的一些有用信息。

Current tech stack:当前技术栈:

  • Nginx nginx
  • Green Unicorn绿色独角兽
  • Flask烧瓶

Of all the different avenues I've tried, the following is the one that seems the most appropriate for the task.在我尝试过的所有不同途径中,以下似乎是最适合该任务的途径。

curl -X POST -F "image=@example.gif" http://54.226.64.199/upload

However, the response is underwhelming.然而,反响平平。

I've tried --uploade-file as well, the response is a 405. From what I've read, upload only accepts a POST command, not PUT, hence why I get a 405.我也试过 --uploade-file,响应是 405。从我读过的内容来看,上传只接受 POST 命令,而不是 PUT,因此我得到 405。

I don't need a full solution (would be great!), only pointing in the right direction.我不需要完整的解决方案(会很棒!),只需要指向正确的方向。

Any help is appreciated.任何帮助表示赞赏。 Thanks谢谢

EDIT: sorry wanted to include part of my .conf编辑:抱歉想包含我的 .conf 的一部分

        location /upload {
        upload_store /tmp;
        #upload_pass @none;
        upload_store_access all:rw;
        upload_cleanup 400 404 499 500-505;

    }

You can do this by specifying filename into URL, without using any external module :您可以通过在 URL 中指定文件名来完成此操作,而无需使用任何外部模块:

location ~ "/upload/([0-9a-zA-Z-.]*)$" {
    alias     /storage/www/upload/$1;
    client_body_temp_path  /tmp/upload_tmp;
    dav_methods  PUT DELETE MKCOL COPY MOVE;
    create_full_put_path   on;
    dav_access             group:rw  all:r;
}

And use : curl -T example.gif http://54.226.64.199/upload/example.gif并使用: curl -T example.gif http://54.226.64.199/upload/example.gif

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

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