All Posts In Nginx

Why Your Nginx PHP Rewrites Might Fail — and How to Fix Them
Adam C. |
This post explains why Nginx PHP rewrites using regex-based location ~ blocks often fail — causing .php files to download instead of execute. It walks through a reliable no-regex solution using prefix-based locations and shows how to fix the regex approach by adding folder-specific .php handlers. Ideal for anyone implementing clean URLs in PHP with Nginx.
WebSocket Upgrade Handling: Apache vs. Nginx
Adam C. |
When handling WebSocket upgrades, Apache and Nginx take different approaches: Apache uses conditional rewrite rules to only send the Upgrade and Connection: upgrade headers when the client actually requests a WebSocket connection, keeping normal HTTP traffic clean and efficient. Nginx, on the other hand, often relies on always setting these headers in proxy configs, which can cause unnecessary overhead or even break normal requests if left unguarded. The key lesson is to handle upgrades conditionally—just like Apache does—so that WebSocket traffic is supported without polluting or disrupting standard HTTP traffic.
Understanding HTTP Header Size Limits in Apache and Nginx
Adam C. |
Both Apache and Nginx enforce limits on HTTP header sizes to prevent abuse, which can trigger confusing 400/431/502 errors when apps use large cookies or JWTs; by default, Apache allows ~8 KB per header in HTTP/1.x and 64 KB total in HTTP/2, while Nginx defaults are even tighter (1 KB per header line, 8 KB response headers), so tuning directives like LimitRequestFieldSize, H2MaxHeaderListSize, client_header_buffer_size, and proxy_buffer_size is often necessary—but keep values reasonable (≈16 KB per header, 128 KB total) to balance real-world needs with memory efficiency and DoS protection.