Best way to save nginx request as file?

I am looking for a solution for saving data sent via http (for example, as POST) as quickly as possible (at the lowest cost) through nginx (v1.2.9). I tried the following nginx configuration but cannot see the 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 achieve this? (The data that needs to be written should ideally be one file for each request, and it does not matter if it is quite raw in nature. Subsequent file processing will be done through a separate process through a queue.)

+6
source share
2 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 to indicate where the stored variable should be reset.

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

It can also work with your method, but I think you are missing client_body_buffer_size and `client_max_body_size

+2
source

Do you mean storing the cache for an HTTP message when someone accesses and requests a file and saves it on hdd and not in memory? I can suggest using proxy_cache_path and proxy_cache. The proxy_cache_path directive sets the path and cache configuration, and the proxy_cache directive activates it.

 proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; server { ... location / { proxy_cache my_cache; proxy_pass http://my_upstream; } } 
  • The local drive directory for the cache is called / path / to / cache Levels
  • set up a two-level directory hierarchy in / path / to / cache /
  • keys_zone sets up a shared memory zone for storing cache keys and metadata, such as usage timers
  • max_size sets an upper limit on cache size
  • inactive indicates how long an item can remain in cache without access

    The proxy_cache directive activates caching of all content that matches the URL of the parent location block (in the example, /). You can also include the proxy_cache directive in the server block; it applies to all location blocks for the server that do not have their own proxy_cache directive.

0
source

Source: https://habr.com/ru/post/988739/


All Articles