fix(nginx): Remove static file extension location block#7
Merged
Conversation
This block serves files matching static extensions directly from disk, bypassing PHP. Any Laravel API route ending in .png, .jpg, etc. never reaches the application — breaking file-serving endpoints and CORS middleware. Redundant since try_files already serves static files from disk. Signed-off-by: nfebe <fenn25.fn@gmail.com>
Code Review SummaryThe PR removes a regex-based location block in Nginx that was intercepting requests for common static file extensions. This fixes a bug where Laravel routes mimicking these extensions (e.g., dynamic image generation or protected file downloads) were returning 404s from Nginx instead of being handled by PHP. 🚀 Key Improvements
💡 Minor Suggestions
|
| add_header Cache-Control "public, immutable"; | ||
| } | ||
|
|
||
| add_header X-Frame-Options "SAMEORIGIN" always; |
There was a problem hiding this comment.
While removing the extension block solves the routing issue, you've lost the browser caching headers (Expires, Cache-Control) for your actual static assets. Consider moving these headers into a general location block or adding them to your main location / if you want to maintain performance for real static files.
Suggested change
| add_header X-Frame-Options "SAMEORIGIN" always; | |
| location / { | |
| try_files $uri $uri/ /index.php?$query_string; | |
| # Re-add caching for static assets here or in a more specific way that doesn't intercept PHP | |
| } | |
| add_header X-Frame-Options "SAMEORIGIN" always; | |
| add_header X-Content-Type-Options "nosniff" always; | |
| add_header X-XSS-Protection "1; mode=block" always; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This block serves files matching static extensions directly from disk, bypassing PHP. Any Laravel API route ending in .png, .jpg, etc. never reaches the application — breaking file-serving endpoints and CORS middleware.
Redundant since try_files already serves static files from disk.