From 2c845461c95700920b794c7b5eb43c9eb546a532 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 13 Mar 2025 20:30:22 +0100 Subject: [PATCH] refactor(nginx): streamline default Nginx configuration and improve error handling Updated the default Nginx configuration function to enhance clarity and maintainability. Removed unnecessary redirection logic and added explicit handling for 404 errors, ensuring a more robust error management strategy. This refactor simplifies the configuration while maintaining essential functionality, contributing to a cleaner and more efficient setup. --- bootstrap/helpers/shared.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 17ddcbda0..db3085649 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -4054,29 +4054,24 @@ function defaultNginxConfiguration(): string { return 'server { location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri.html $uri/index.html $uri/index.htm $uri/ /index.html /index.htm =404; + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri.html $uri/index.html $uri/index.htm $uri/ =404; } + # Handle 404 errors + error_page 404 /404.html; + location = /404.html { + root /usr/share/nginx/html; + internal; + } + + # Handle server errors (50x) error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; - try_files $uri @redirect_to_index; internal; } - - error_page 404 = @handle_404; - - location @handle_404 { - root /usr/share/nginx/html; - try_files /404.html @redirect_to_index; - internal; - } - - location @redirect_to_index { - return 302 /; - } }'; }