nginx.conf 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. worker_processes 1;
  2. events {
  3. worker_connections 1024;
  4. }
  5. http {
  6. lua_shared_dict limit_cache 10m;
  7. include mime.types;
  8. default_type application/octet-stream;
  9. sendfile on;
  10. keepalive_timeout 65;
  11. client_max_body_size 1024m;
  12. upstream minio-server {
  13. server 117.73.3.135:9000;
  14. }
  15. lua_package_path "/usr/local/openresty/nginx/conf/lua/?.lua;;";
  16. server {
  17. listen 83;
  18. server_name localhost;
  19. location /download {
  20. set_by_lua_block $tenant_id {
  21. return ngx.var.arg_tenant_id or "default"
  22. }
  23. set_by_lua_block $file_key {
  24. return ngx.var.arg_file_key
  25. }
  26. access_by_lua_block {
  27. local limiter = require "bandwidth_limiter"
  28. local proxy = require "file_proxy"
  29. local tenant_id = ngx.var.tenant_id
  30. local file_key = ngx.var.file_key
  31. local rate = limiter.register_device(tenant_id)
  32. ngx.var.limit_rate = rate
  33. ngx.ctx.tenant_id = tenant_id
  34. local url = proxy.get_minio_url(file_key)
  35. if not url then
  36. return ngx.exit(400)
  37. end
  38. local parsed = url:match("https?://[^/]+(/.+)")
  39. if not parsed then
  40. return ngx.exit(400)
  41. end
  42. return ngx.exec("/internal_minio" .. parsed)
  43. }
  44. log_by_lua_block {
  45. local limiter = require "bandwidth_limiter"
  46. if ngx.ctx.tenant_id then
  47. limiter.unregister_device(ngx.ctx.tenant_id)
  48. end
  49. }
  50. }
  51. # ´úÀí MinIO µÄÄÚ²¿ location
  52. location ~ ^/internal_minio/(.*)$ {
  53. internal;
  54. limit_rate $limit_rate;
  55. proxy_pass http://minio-server/$1;
  56. proxy_set_header Host $host;
  57. }
  58. }
  59. }