Regex match the middle of a URL and also the ending?

Jore community at thoughtmaybe.com
Sat Jun 3 14:26:55 UTC 2023


Hi all,

I have an app on a domain that is set by a developer to proxy at certain 
URLs:

|example.com/browser/123foo0/stuff.js |

for example, where |123foo0| is some random key. The key may also change 
length in future.

That’s all fine.

But I’d like to interrupt specific requests and not proxy them: I don’t 
want to serve anything after the key that is in the path |/welcome| for 
example, i.e. not proxy any of these:

|example.com/browser/123foo0/welcome/welcome.html 
example.com/browser/foo456b/welcome/welcome.css 
example.com/browser/bar123f/welcome/welcome.js 
example.com/browser/456foob/welcome/other.stuff 
example.com/browser/foo789b/welcome/ |

So I tried simple stuff first like: |location ^~ 
/browser/.*/welcome/welcome.html {...|
but couldn’t even get that working, before moving on to try capturing 
groups like css files and scripts and so on.

I also tried putting regex in quotes, but that didn’t seem to work either.

What am I doing wrong?

Here’s a truncated version of the conf, with the location blocks only:

|location ^~ "/browser/.*/welcome/welcome.html" { return 200 'Not 
proxied.\n'; add_header Content-Type text/plain; } location ^~ /browser 
{ proxy_pass http://127.0.0.1:1234; proxy_set_header Host $http_host; } 
# landing page location / { root /var/www/foobar; index index.html; 
try_files $uri $uri/ /index.html; } |

Thanks,
Jore


​

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230604/c659abb5/attachment.htm>


More information about the nginx mailing list