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.prod.conf 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # Nginx configuration for production environment
  2. # HTTP to HTTPS redirect, SSL/TLS, WebSocket support
  3. user nginx;
  4. worker_processes auto;
  5. error_log /var/log/nginx/error.log warn;
  6. pid /var/run/nginx.pid;
  7. events {
  8. worker_connections 2048;
  9. use epoll;
  10. }
  11. http {
  12. include /etc/nginx/mime.types;
  13. default_type application/octet-stream;
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_size_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main;
  18. sendfile on;
  19. tcp_nopush on;
  20. tcp_nodelay on;
  21. keepalive_timeout 65;
  22. types_hash_max_size 2048;
  23. client_max_body_size 50M;
  24. # Hide nginx version
  25. server_tokens off;
  26. # Gzip compression
  27. gzip on;
  28. gzip_vary on;
  29. gzip_proxied any;
  30. gzip_comp_level 6;
  31. gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss;
  32. # Rate limiting (optional, adjust as needed)
  33. limit_req_zone $binary_remote_addr zone=api_limit:10m rate=100r/m;
  34. limit_req_zone $binary_remote_addr zone=ws_limit:10m rate=10r/s;
  35. # Upstream API server
  36. upstream api {
  37. server api:3000;
  38. keepalive 32;
  39. }
  40. # HTTP server - redirect to HTTPS
  41. server {
  42. listen 80;
  43. server_name _;
  44. # Allow Let's Encrypt challenges
  45. location /.well-known/acme-challenge/ {
  46. root /var/www/certbot;
  47. }
  48. # Redirect all other traffic to HTTPS
  49. location / {
  50. return 301 https://$host$request_uri;
  51. }
  52. }
  53. # HTTPS server
  54. server {
  55. listen 443 ssl http2;
  56. server_name _;
  57. # SSL Configuration
  58. # Update these paths to match your SSL certificate locations
  59. ssl_certificate /etc/nginx/ssl/certs/fullchain.pem;
  60. ssl_certificate_key /etc/nginx/ssl/private/privkey.pem;
  61. # SSL Security Settings
  62. ssl_protocols TLSv1.2 TLSv1.3;
  63. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
  64. ssl_prefer_server_ciphers off;
  65. ssl_session_cache shared:SSL:10m;
  66. ssl_session_timeout 10m;
  67. ssl_session_tickets off;
  68. # Security Headers
  69. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
  70. add_header X-Frame-Options "DENY" always;
  71. add_header X-Content-Type-Options "nosniff" always;
  72. add_header X-XSS-Protection "1; mode=block" always;
  73. add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  74. # Health check endpoint (no rate limiting)
  75. location /health {
  76. proxy_pass http://api/health;
  77. proxy_http_version 1.1;
  78. proxy_set_header Host $host;
  79. proxy_set_header X-Real-IP $remote_addr;
  80. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  81. proxy_set_header X-Forwarded-Proto $scheme;
  82. access_log off;
  83. }
  84. # WebSocket support for Socket.io (with rate limiting)
  85. location /socket.io/ {
  86. limit_req zone=ws_limit burst=20 nodelay;
  87. proxy_pass http://api;
  88. proxy_http_version 1.1;
  89. # WebSocket upgrade headers
  90. proxy_set_header Upgrade $http_upgrade;
  91. proxy_set_header Connection "upgrade";
  92. # Standard proxy headers
  93. proxy_set_header Host $host;
  94. proxy_set_header X-Real-IP $remote_addr;
  95. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  96. proxy_set_header X-Forwarded-Proto $scheme;
  97. # WebSocket timeouts (Socket.io uses long-lived connections)
  98. proxy_read_timeout 86400s;
  99. proxy_send_timeout 86400s;
  100. proxy_connect_timeout 60s;
  101. # Disable buffering for real-time data
  102. proxy_buffering off;
  103. proxy_cache off;
  104. }
  105. # API endpoints (with rate limiting)
  106. location /api/ {
  107. limit_req zone=api_limit burst=50 nodelay;
  108. proxy_pass http://api;
  109. proxy_http_version 1.1;
  110. proxy_set_header Host $host;
  111. proxy_set_header X-Real-IP $remote_addr;
  112. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  113. proxy_set_header X-Forwarded-Proto $scheme;
  114. # Timeout settings
  115. proxy_connect_timeout 60s;
  116. proxy_send_timeout 60s;
  117. proxy_read_timeout 60s;
  118. # Buffer settings
  119. proxy_buffering on;
  120. proxy_buffer_size 4k;
  121. proxy_buffers 8 4k;
  122. }
  123. # Root endpoint
  124. location / {
  125. proxy_pass http://api;
  126. proxy_http_version 1.1;
  127. proxy_set_header Host $host;
  128. proxy_set_header X-Real-IP $remote_addr;
  129. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  130. proxy_set_header X-Forwarded-Proto $scheme;
  131. }
  132. }
  133. }