| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- # Logging
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log logs/access.log main;
- error_log logs/error.log;
- # Basic settings
- sendfile on;
- tcp_nopush on;
- tcp_nodelay on;
- keepalive_timeout 65;
- types_hash_max_size 2048;
- # Gzip compression
- gzip on;
- gzip_vary on;
- gzip_min_length 1024;
- gzip_types
- text/plain
- text/css
- text/xml
- text/javascript
- application/json
- application/javascript
- application/xml+rss
- application/atom+xml;
- # Rate limiting (optional)
- limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
- limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
- # Upstream server (your Node.js API)
- upstream market_data_api {
- server localhost:3001;
- keepalive 32;
- }
- # HTTP server block for port 80
- server {
- listen 80;
- server_name marketData;
- # Security headers
- add_header X-Frame-Options DENY;
- add_header X-Content-Type-Options nosniff;
- add_header X-XSS-Protection "1; mode=block";
- # Proxy settings for API calls
- location /api/ {
- # Apply rate limiting
- limit_req zone=api burst=20 nodelay;
- # Proxy to Node.js server
- proxy_pass http://market_data_api/;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection 'upgrade';
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_cache_bypass $http_upgrade;
- # Timeout settings
- proxy_connect_timeout 60s;
- proxy_send_timeout 60s;
- proxy_read_timeout 60s;
- # Buffer settings for large payloads
- proxy_buffering on;
- proxy_buffer_size 4k;
- proxy_buffers 8 4k;
- proxy_busy_buffers_size 8k;
- client_max_body_size 50M;
- # Enable all HTTP methods
- if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE|OPTIONS)$ ) {
- return 405;
- }
- }
- # Health check endpoint (optional)
- location /health {
- proxy_pass http://market_data_api/health;
- proxy_http_version 1.1;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- }
- # Root location - serve a simple status page or redirect
- location / {
- return 200 "Nginx is running. API endpoints available at /api/\n";
- add_header Content-Type text/plain;
- }
- # Error pages
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- # Optional HTTPS server block (for future use)
- # server {
- # listen 443 ssl http2;
- # server_name localhost;
- #
- # # SSL configuration would go here
- #
- # location /api/ {
- # proxy_pass http://market_data_api/;
- # # ... same proxy settings as above
- # }
- # }
- }
|