Story Details

  • Nginx: try_files Is Evil Too (2024)

    Posted: 2025-02-17 13:18:16

    The blog post "Nginx: try_files is evil too" argues against using the try_files directive in Nginx configurations, especially for serving static files. While seemingly simple, its behavior can be unpredictable and lead to unexpected errors, particularly when dealing with rewritten URLs or if file existence checks are bypassed due to caching. The author advocates for using simpler, more explicit location blocks to define how different types of requests should be handled, leading to improved clarity, maintainability, and potentially better performance. They suggest separate location blocks for specific file types and a final catch-all block for dynamic requests, promoting a more transparent and less error-prone approach to configuration.

    Summary of Comments ( 4 )
    https://news.ycombinator.com/item?id=43078696

    Hacker News commenters largely disagree with the article's premise that try_files is inherently "evil." Several point out that the author's proposed alternative using location blocks with regular expressions is less performant and more complex, especially for simpler use cases. Some argue that the author mischaracterizes try_files's purpose, which is primarily for serving static files efficiently, not complex routing. Others agree that try_files can be misused, leading to confusing configurations, but contend that when used appropriately, it's a valuable tool. The discussion also touches on alternative approaches, such as using a separate frontend proxy or load balancer for more intricate routing logic. A few commenters express appreciation for the article prompting a re-evaluation of their Nginx configurations, even if they don't fully agree with the author's conclusions.