diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..1e5c23d9 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,10 @@ +version: '3.9' + +services: + nginx: + # Use HTTP-only Nginx config for local development + volumes: + - ./services/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro + # Expose only port 80 locally; HTTPS (443) not needed in dev + ports: + - "80:80" diff --git a/services/nginx/nginx.dev.conf b/services/nginx/nginx.dev.conf new file mode 100644 index 00000000..eb8c63aa --- /dev/null +++ b/services/nginx/nginx.dev.conf @@ -0,0 +1,74 @@ +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Structured JSON access logs and correlation id + map $http_x_request_id $req_id { default $http_x_request_id; "" $request_id; } + log_format json escape=json '{"time":"$time_iso8601","req_id":"$req_id","remote":"$remote_addr","host":"$host","method":"$request_method","uri":"$request_uri","status":$status,"bytes":$bytes_sent,"referer":"$http_referer","ua":"$http_user_agent","up_addr":"$upstream_addr","up_st":"$upstream_status","up_rt":$upstream_response_time,"rt":$request_time}'; + + # Log settings + access_log /var/log/nginx/access.ndjson json; + error_log /var/log/nginx/error.log warn; + + # Gzip settings (optional) + gzip on; + gzip_disable "msie6"; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain application/xml text/css application/javascript application/json application/x-javascript text/javascript; + + # Upstream pool for PHP-FPM (load-balanced) + upstream php_fpm { + least_conn; + server php1:9000 max_fails=3 fail_timeout=10s; + server php2:9000 max_fails=3 fail_timeout=10s; + keepalive 32; + } + + # HTTP server (no HTTPS for local development) + server { + listen 80; + server_name _; + + # Logging headers + add_header X-Request-Id $req_id always; + + # Root and index + root /var/www/html; + index index.php index.html index.htm; + + # Main application location + location / { + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"; + add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With, X-Customer-Number"; + add_header Access-Control-Allow-Credentials true; + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"; + add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With, X-Customer-Number"; + return 204; + } + + include fastcgi_params; + fastcgi_pass php_fpm; + fastcgi_index index.php; + fastcgi_read_timeout 60s; + fastcgi_param SCRIPT_FILENAME $document_root/index.php; + fastcgi_param X_REQUEST_ID $req_id; + fastcgi_keep_conn on; + } + + # Deny access to hidden files + location ~ /\. { deny all; } + location ~ /\.ht { deny all; } + } +}