nginx.conf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. events {
  2. worker_connections 2048;
  3. use epoll;
  4. multi_accept on;
  5. }
  6. http {
  7. # Required basic settings
  8. include /etc/nginx/mime.types;
  9. default_type application/octet-stream;
  10. # Logging settings
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" "$http_x_forwarded_for"';
  14. access_log /var/log/nginx/access.log main;
  15. # Connection optimization
  16. sendfile on;
  17. tcp_nopush on;
  18. tcp_nodelay on;
  19. keepalive_timeout 65;
  20. upstream r2r_backend {
  21. least_conn;
  22. server r2r:7272 max_fails=3 fail_timeout=30s; # Use service name instead of container names
  23. keepalive 32;
  24. }
  25. server {
  26. listen 80;
  27. server_name localhost;
  28. # Timeouts
  29. proxy_connect_timeout 300s;
  30. proxy_send_timeout 300s;
  31. proxy_read_timeout 300s;
  32. # Buffer settings
  33. proxy_buffers 8 16k;
  34. proxy_buffer_size 32k;
  35. location / {
  36. proxy_pass http://r2r_backend;
  37. proxy_http_version 1.1;
  38. proxy_set_header Upgrade $http_upgrade;
  39. proxy_set_header Connection 'upgrade';
  40. proxy_set_header Host $host;
  41. proxy_set_header X-Real-IP $remote_addr;
  42. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  43. proxy_set_header X-Forwarded-Proto $scheme;
  44. # Retry settings
  45. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
  46. proxy_next_upstream_tries 3;
  47. proxy_next_upstream_timeout 10s;
  48. }
  49. location /health {
  50. access_log off;
  51. add_header 'Content-Type' 'application/json';
  52. return 200 '{"status":"healthy"}';
  53. }
  54. # Error responses
  55. error_page 500 502 503 504 /50x.html;
  56. location = /50x.html {
  57. root /usr/share/nginx/html;
  58. }
  59. }
  60. }