server_tokens off;
map $uri $hub_safe_uri {
 ~^/reset-password/ /reset-password/[redacted];
 ~^/team/invitations/ /team/invitations/[redacted];
 default $uri;
}
log_format hub_safe '$remote_addr $request_method $hub_safe_uri $status $request_time';
fastcgi_hide_header X-Content-Type-Options;
fastcgi_hide_header X-Frame-Options;
fastcgi_hide_header Referrer-Policy;
fastcgi_hide_header Permissions-Policy;
map $server_port $hub_edge_budget { default $server_port; }
limit_req_zone $binary_remote_addr zone=hub_edge_ip:10m rate=50r/s;
limit_req_zone $hub_edge_budget zone=hub_edge_total:1m rate=200r/s;
limit_conn_zone $binary_remote_addr zone=hub_edge_connections:10m;
limit_conn_zone $hub_edge_budget zone=hub_edge_total_connections:1m;
limit_req_status 429;
limit_conn_status 429;
limit_req_log_level info;
limit_conn_log_level info;
resolver 127.0.0.11 valid=5s ipv6=off;
upstream hub_public { zone hub_public 64k; server hub:9000 resolve; keepalive 16; }
upstream hub_internal { zone hub_internal 64k; server hub:9001 resolve; keepalive 8; }
server {
 listen 8080;
 limit_req zone=hub_edge_ip burst=100 nodelay;
 limit_req zone=hub_edge_total burst=400 nodelay;
 limit_conn hub_edge_connections 64;
 limit_conn hub_edge_total_connections 256;
 access_log /var/log/nginx/access.log hub_safe;
 add_header X-Content-Type-Options nosniff always;
 add_header X-Frame-Options DENY always;
 add_header Referrer-Policy no-referrer always;
 add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), usb=()" always;
 root /srv/iphub/apps/hub/public;
 index index.php;
 client_max_body_size 1m;
 client_body_timeout 5s;
 client_header_timeout 5s;
 location ~ /\. { deny all; }
 location ~* ^/(?:internal|storage|vendor|\.env) { return 404; }
 location / { try_files $uri $uri/ /index.php?$query_string; }
 location = /index.php { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /srv/iphub/apps/hub/public/index.php; fastcgi_param HTTP_PROXY ''; fastcgi_param HUB_ROLE public; fastcgi_param HTTPS $https if_not_empty; fastcgi_pass hub_public; fastcgi_read_timeout 8s; fastcgi_buffering on; }
 location ~ \.php$ { return 404; }
}
server {
 listen 8081;
 limit_req zone=hub_edge_total burst=400 nodelay;
 limit_conn hub_edge_total_connections 128;
 access_log /var/log/nginx/access.log hub_safe;
 add_header X-Content-Type-Options nosniff always;
 add_header X-Frame-Options DENY always;
 add_header Referrer-Policy no-referrer always;
 add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), usb=()" always;
 client_max_body_size 256k;
 client_body_timeout 3s;
 client_header_timeout 3s;
 location /internal/ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /srv/iphub/apps/hub/public/index.php; fastcgi_param HTTP_PROXY ''; fastcgi_param HUB_ROLE internal; fastcgi_param HTTPS $https if_not_empty; fastcgi_pass hub_internal; fastcgi_read_timeout 6s; }
 location / { return 404; }
}
