brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ^~ in a nginx location stops regex locations from taking the request

Nginx
~/tips/tip-nginx-caret-tilde-location

location ^~ /uploads/ { root /var/www; }

Makes a prefix location final so no regex location can take over its requests.

A regex location can quietly win over a plain prefix location, and that matters most for upload folders.

location ^~ /uploads/ { root /var/www; }
location ~* \.php$ { fastcgi_pass unix:/run/php/php-fpm.sock; }

nginx picks the longest matching prefix location first. If that prefix carries ^~, regex locations are skipped. Without it, ~* \.php$ still gets a request for /uploads/shell.php and passes it to PHP. Order of checks: = exact match, then the longest prefix, then regexes in file order, then the stored prefix. Test with a request to a file in the folder and see which block answers.

Further reading: ngx_http_core_module: location

Going deeper: ๐Ÿ›œ Guide: AdGuard Home + Tailscale (Secure Split-Horizon DNS)

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link