Score:1

Wildcard path to serve Static resources

ie flag

I want to access resources like images in a directory with the endpoint that has a token in middle of the path.

http://example.com/contextpath/<token>/logos/myLogo.png

Example: http://example.com/contextpath/abc1234/logos/myLogo.png

I am trying to configure it in nginx.conf and put this config to point the resource to a directory:

location ~ ^/contextpath/(logos/.*) {
    root      "C:/temp/logos";
}

But its not working.

Richard Smith avatar
jp flag
The regular expression does not match your example URL. Are you trying to ignore the token or capture it?
jodevelofer avatar
ie flag
@RichardSmith I want to capture it also, but if not possible Its ok to ignore it for now. As long as the resource will served.
Richard Smith avatar
jp flag
Where is the file located in your example? `C:/temp/logos/myLogo.png` - with both `contextpath` and `<token>` removed?
jodevelofer avatar
ie flag
@RichardSmith yes
Score:0
jp flag

To deliver the file at C:/temp/logos/myLogo.png in response to the URL http://example.com/contextpath/abc1234/logos/myLogo.png (where the text token abc1234 is unknown) you should use a regular expression location together with try_files.

For example:

location ~ ^/contextpath/[^/]+/logos(/.*)$ {
    root "C:/temp/logos";
    try_files $1 =404;
}

The /[^/]+/ sequence matches any token between two /s.

The text "logos" should either appear in the capture or in the root statement - not both as in your example.

See the try_files directive.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.