How to configure NGINX virtual host (vhost) to serve the same image (/images/game-board.png) for all image requests that start with a specific string like /images/game-board-?
Example:
For these image requests:
- /images/game-board-is89sj.png
- /images/game-board-32jsds.png
- /images/game-board-abcx7v.png
Serve this file:
- /images/game-board.png
I've tried the below location block configurations. But they are not working.
location ~ ^/images/game-board-[^/]+\.png$ { alias /var/www/html/images/game-board.png; } location ~ ^/images/game-board-[^/]+\.png$ { try_files $uri /images/game-board.png; } Update:
Ok, I found the solution. The issue was with the priority of the location blocks. Moving the alias location block above the other location blocks (which had catch-all image rules) worked for me.