Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to save nginx request as a file?

i am looking for a solution to save data sent via http (e.g. as a POST) as quickly as possible (with lowest overhead) via nginx (v1.2.9). i tried the following nginx configuration, but am not seeing any files written in the directory:

server {
  listen 9199;
  location /saveme {
    client_body_in_file_only on;
    client_body_temp_path /tmp/bodies;
  }
}

what am i doing wrong? and/or is there a better way to accomplish this? (the data that is written should ideally be one file per request, and it does not matter if it is fairly "raw" in nature. post-processing of the files will be done via a separate process via a queue.)

like image 972
Mumonkan Avatar asked Jun 08 '15 20:06

Mumonkan


People also ask

Where to put files for nginx?

By default the file is named nginx. conf and for NGINX Plus is placed in the /etc/nginx directory. (For NGINX Open Source , the location depends on the package system used to install NGINX and the operating system. It is typically one of /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.)

How do I use nginx as a file server?

Serving static files using nginx as web server is a good option. For making the static files available you need to copy your testfolder to /usr/share/nginx/html inside the nginx image. After which you will be able to see the files on your browser on port 8080.

What is Sendfile nginx?

The nginx HTTP server has a directive named sendfile , which can tell it to use the Linux sendfile() system call to do I/O without copying to an intermediate memory buffer. That should increase the I/O rate and reduce memory use.


1 Answers

This question has already been answered here:

Basically, you need to combine log_format and fastcgi_pass. You can then use the access_log directive for example, to specify where the saved variable should be dumped to.

location = /saveme {
  log_format postdata $request_body;
  access_log  /var/log/nginx/postdata.log  postdata;
  fastcgi_pass php_cgi;
}

It could also work with your method but I think you're missing client_body_buffer_size and `client_max_body_size

like image 165
Chibueze Opata Avatar answered Sep 17 '22 01:09

Chibueze Opata