0

I want NGINX to serve serve files from a location within a server. As an example, I would like the url http://domain/ss/image.png to serve the file located within /home/data/screenshots/image.png

So far, I have attempted to use a regex in this manner

location ~ ^/ss/(.*) {
    root /home/data/screenshots;
    add_header content-type "image/png";
    try_files $1 /$1;
}

however it appears that this location is never reached, being handled by the location spefcified to / (which in my case is a redirect).

I am not flexible with renaming/changing any of the file structure of the project and want to achieve this result with just the NGINX config modification.

2
  • The $1 will not match as it is missing a leading / and the final parameter of try_files is an internal redirect which will be handled by the location / block. You should try: try_files /$1 =404; Commented Dec 2, 2021 at 14:28
  • Hi! This appears to have solved my issue! Thank you! Commented Dec 2, 2021 at 14:46

1 Answer 1

1

As described by Richard's comment on the question, it appears that my regex approach was correct, however my issue was the usage of the try_files function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.