薄+ Nginx +上传模块 +上传进度模块

发布于 2024-10-18 06:35:19 字数 894 浏览 1 评论 0原文

我使用 Nginx 作为 Thin 实例的反向代理。

我的目标是建立一个 Rails (3) 应用程序来上传大文件并对其执行某些操作。

为此,我遇到了 Nginx Upload 和 Upload Progress 模块。

我大部分时间都在阅读 这篇 帖子,但那是专门在 Passenger 中写的思考。

如果可能,我正在寻找两个可能的答案:

1)信息实现此堆栈的示例(使用 Thin 而不是 Passenger)

2)如何重写此信息的具体信息:

   location ^~ /progress {
         # report uploads tracked in the 'proxied' zone
         upload_progress_json_output;
         report_uploads proxied;
       }

       location @fast_upload_endpoint {
         passenger_enabled on;
         rails_env development;
       }

       location / {
         rails_env development;
         passenger_enabled on;
       }

我不知道 Passenger 独有的是什么,以及如何为典型的 4 个工作线程/3 个瘦实例conf 编写它。

谢谢。

I'm using Nginx as a reverse proxy for Thin instances.

My goal is to set up a Rails (3) app to upload large files and do something with them.

For that, I came across the Nginx Upload and Upload Progress modules.

I was reading, for the most part, this post, but that's specifically wrote thinking in Passenger.

If possible, I'm looking for two possible answers:

1) Information an examples of implementing this stack (with Thin instead of Passenger)

2) Specific Information of how could I rewrite this:

   location ^~ /progress {
         # report uploads tracked in the 'proxied' zone
         upload_progress_json_output;
         report_uploads proxied;
       }

       location @fast_upload_endpoint {
         passenger_enabled on;
         rails_env development;
       }

       location / {
         rails_env development;
         passenger_enabled on;
       }

I don't know what is Passenger exclusive, and how to write it for a typical 4 workers / 3 thin instances conf.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双手揣兜 2024-10-25 06:35:19

首先,您应该安装 nginx 和上传模块。站点的 nginx 配置:

upstream uploader_cluster {
  server unix:/tmp/thin.uploader.0.sock;
  server unix:/tmp/thin.uploader.1.sock;
  server unix:/tmp/thin.uploader.2.sock;
  server unix:/tmp/thin.uploader.3.sock;
  server unix:/tmp/thin.uploader.4.sock;
}

server {
     listen 80;
     server_name ***.com;

     charset off;
     client_max_body_size 1000m;

     access_log /var/www/uploader/log/access.log;
     error_log /var/www/uploader/log/error.log;

     root /var/www/uploader/public;
     index index.html;

     location / {
         proxy_redirect     off;
         proxy_set_header   Host             $host;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

         if (-f $request_filename/index.html) {
             rewrite (.*) $1/index.html break;
         }

         if (-f $request_filename.html) {
             rewrite (.*) $1.html break;
         }

         if (!-f $request_filename) {
             proxy_pass http://uploader_cluster;
             break;
         }
     }

     location ~*uploads$ {
        if ($request_method = GET) {
          proxy_pass http://uploader_cluster;
          break;
        }

        # pass request body to here
        upload_pass @upload_photos;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
        # i.e. make sure to create /vol/uploads/0 /vol/uploads/1 etc.
        upload_store /vol/uploads 1;

        # set permissions on the uploaded files
        upload_store_access user:rw group:rw all:r;

        # Set specified fields in request body
        # this puts the original filename, new path+filename and content type in the requests params
        upload_set_form_field upload[file_name] "$upload_file_name";
        upload_set_form_field upload[file_content_type] "$upload_content_type";
        upload_set_form_field upload[file_path] "$upload_tmp_path";
        upload_aggregate_form_field upload[file_size] "$upload_file_size";

        upload_pass_form_field "^fb_sig_user$|^aid$|^batch_id$|^album_name$|^album_visible$|^caption$|^tags$|^complete$";

        upload_cleanup 400 404 499 500-505;
     }

     location @upload_photos {
        proxy_pass http://uploader_cluster;
     }
}

First, you should install nginx with the upload module. The nginx config for site:

upstream uploader_cluster {
  server unix:/tmp/thin.uploader.0.sock;
  server unix:/tmp/thin.uploader.1.sock;
  server unix:/tmp/thin.uploader.2.sock;
  server unix:/tmp/thin.uploader.3.sock;
  server unix:/tmp/thin.uploader.4.sock;
}

server {
     listen 80;
     server_name ***.com;

     charset off;
     client_max_body_size 1000m;

     access_log /var/www/uploader/log/access.log;
     error_log /var/www/uploader/log/error.log;

     root /var/www/uploader/public;
     index index.html;

     location / {
         proxy_redirect     off;
         proxy_set_header   Host             $host;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

         if (-f $request_filename/index.html) {
             rewrite (.*) $1/index.html break;
         }

         if (-f $request_filename.html) {
             rewrite (.*) $1.html break;
         }

         if (!-f $request_filename) {
             proxy_pass http://uploader_cluster;
             break;
         }
     }

     location ~*uploads$ {
        if ($request_method = GET) {
          proxy_pass http://uploader_cluster;
          break;
        }

        # pass request body to here
        upload_pass @upload_photos;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
        # i.e. make sure to create /vol/uploads/0 /vol/uploads/1 etc.
        upload_store /vol/uploads 1;

        # set permissions on the uploaded files
        upload_store_access user:rw group:rw all:r;

        # Set specified fields in request body
        # this puts the original filename, new path+filename and content type in the requests params
        upload_set_form_field upload[file_name] "$upload_file_name";
        upload_set_form_field upload[file_content_type] "$upload_content_type";
        upload_set_form_field upload[file_path] "$upload_tmp_path";
        upload_aggregate_form_field upload[file_size] "$upload_file_size";

        upload_pass_form_field "^fb_sig_user$|^aid$|^batch_id$|^album_name$|^album_visible$|^caption$|^tags$|^complete$";

        upload_cleanup 400 404 499 500-505;
     }

     location @upload_photos {
        proxy_pass http://uploader_cluster;
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文