Market Data Service is a high-performance financial data API that provides comprehensive Symbol prices of different markets through both RESTful endpoints and real-time WebSocket connections.

nginx.conf 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. events {
  2. worker_connections 1024;
  3. }
  4. http {
  5. include mime.types;
  6. default_type application/octet-stream;
  7. # Logging
  8. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  9. '$status $body_bytes_sent "$http_referer" '
  10. '"$http_user_agent" "$http_x_forwarded_for"';
  11. access_log logs/access.log main;
  12. error_log logs/error.log;
  13. # Basic settings
  14. sendfile on;
  15. tcp_nopush on;
  16. tcp_nodelay on;
  17. keepalive_timeout 65;
  18. types_hash_max_size 2048;
  19. # Gzip compression
  20. gzip on;
  21. gzip_vary on;
  22. gzip_min_length 1024;
  23. gzip_types
  24. text/plain
  25. text/css
  26. text/xml
  27. text/javascript
  28. application/json
  29. application/javascript
  30. application/xml+rss
  31. application/atom+xml;
  32. # Rate limiting (optional)
  33. limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
  34. limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
  35. # Upstream server (your Node.js API)
  36. upstream market_data_api {
  37. server localhost:3001;
  38. keepalive 32;
  39. }
  40. # HTTP server block for port 80
  41. server {
  42. listen 80;
  43. server_name marketData;
  44. # Security headers
  45. add_header X-Frame-Options DENY;
  46. add_header X-Content-Type-Options nosniff;
  47. add_header X-XSS-Protection "1; mode=block";
  48. # Proxy settings for API calls
  49. location /api/ {
  50. # Apply rate limiting
  51. limit_req zone=api burst=20 nodelay;
  52. # Proxy to Node.js server
  53. proxy_pass http://market_data_api/;
  54. proxy_http_version 1.1;
  55. proxy_set_header Upgrade $http_upgrade;
  56. proxy_set_header Connection 'upgrade';
  57. proxy_set_header Host $host;
  58. proxy_set_header X-Real-IP $remote_addr;
  59. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  60. proxy_set_header X-Forwarded-Proto $scheme;
  61. proxy_cache_bypass $http_upgrade;
  62. # Timeout settings
  63. proxy_connect_timeout 60s;
  64. proxy_send_timeout 60s;
  65. proxy_read_timeout 60s;
  66. # Buffer settings for large payloads
  67. proxy_buffering on;
  68. proxy_buffer_size 4k;
  69. proxy_buffers 8 4k;
  70. proxy_busy_buffers_size 8k;
  71. client_max_body_size 50M;
  72. # Enable all HTTP methods
  73. if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE|OPTIONS)$ ) {
  74. return 405;
  75. }
  76. }
  77. # Health check endpoint (optional)
  78. location /health {
  79. proxy_pass http://market_data_api/health;
  80. proxy_http_version 1.1;
  81. proxy_set_header Host $host;
  82. proxy_set_header X-Real-IP $remote_addr;
  83. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  84. proxy_set_header X-Forwarded-Proto $scheme;
  85. }
  86. # Root location - serve a simple status page or redirect
  87. location / {
  88. return 200 "Nginx is running. API endpoints available at /api/\n";
  89. add_header Content-Type text/plain;
  90. }
  91. # Error pages
  92. error_page 500 502 503 504 /50x.html;
  93. location = /50x.html {
  94. root html;
  95. }
  96. }
  97. # Optional HTTPS server block (for future use)
  98. # server {
  99. # listen 443 ssl http2;
  100. # server_name localhost;
  101. #
  102. # # SSL configuration would go here
  103. #
  104. # location /api/ {
  105. # proxy_pass http://market_data_api/;
  106. # # ... same proxy settings as above
  107. # }
  108. # }
  109. }