nginx.conf 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. worker_processes auto;
  2. error_log /tmp/nginx_error.log warn;
  3. pid /tmp/nginx.pid;
  4. events {
  5. worker_connections 1024;
  6. use epoll;
  7. multi_accept on;
  8. }
  9. http {
  10. include /etc/nginx/mime.types;
  11. default_type application/octet-stream;
  12. # Temp directories for non-root
  13. client_body_temp_path /tmp/client_temp;
  14. proxy_temp_path /tmp/proxy_temp;
  15. fastcgi_temp_path /tmp/fastcgi_temp;
  16. uwsgi_temp_path /tmp/uwsgi_temp;
  17. scgi_temp_path /tmp/scgi_temp;
  18. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. '$status $body_bytes_sent "$http_referer" '
  20. '"$http_user_agent" "$http_x_forwarded_for"';
  21. access_log /tmp/nginx_access.log main;
  22. # Performance
  23. sendfile on;
  24. tcp_nopush on;
  25. tcp_nodelay on;
  26. keepalive_timeout 65;
  27. types_hash_max_size 2048;
  28. # Gzip compression
  29. gzip on;
  30. gzip_vary on;
  31. gzip_proxied any;
  32. gzip_comp_level 6;
  33. gzip_min_length 1024;
  34. gzip_types text/plain text/css text/xml text/javascript
  35. application/json application/javascript application/xml
  36. application/rss+xml application/atom+xml image/svg+xml;
  37. # Security
  38. server_tokens off;
  39. server {
  40. listen 8080;
  41. server_name _;
  42. root /usr/share/nginx/html;
  43. index index.html;
  44. # Security headers
  45. add_header X-Frame-Options "SAMEORIGIN" always;
  46. add_header X-Content-Type-Options "nosniff" always;
  47. add_header X-XSS-Protection "1; mode=block" always;
  48. add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  49. # Health check endpoint
  50. location /health {
  51. access_log off;
  52. return 200 "healthy\n";
  53. add_header Content-Type text/plain;
  54. }
  55. # Static assets with aggressive caching
  56. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  57. expires 1y;
  58. add_header Cache-Control "public, immutable";
  59. access_log off;
  60. }
  61. # SPA fallback - serve index.html for all routes
  62. location / {
  63. try_files $uri $uri/ /index.html;
  64. }
  65. # No cache for index.html
  66. location = /index.html {
  67. expires -1;
  68. add_header Cache-Control "no-store, no-cache, must-revalidate";
  69. }
  70. # Deny access to hidden files
  71. location ~ /\. {
  72. deny all;
  73. access_log off;
  74. log_not_found off;
  75. }
  76. }
  77. }