How do I configure nginx multipathing?

1. Question & background

there are three paths:

  1. / prefix
  2. / prefix/dist
  3. / prefix/ non-dist non-empty

demand:

  1. http://www.abc.com/prefix or http://www.abc.com/prefix/ can visit index.html
  2. http://www.abc.com/prefix/dist/static/js/vendor.js can access static resources
  3. http://www.abc.com/prefix/coupon/v1( can be understood as prefix, non-dist non-empty case) forwarded to the backend service

loading order of files:

  1. request http://www.abc.com/prefix load index.html
  2. request http://www.abc.com/prefix/dist/static/js/vendor.js
  3. request http://www.abc.com/prefix/coupon/v1

2. My implementation

  the pcretest method verification introduced in this article , the regular writing is also error-free 
  • but when running, it still matches http://www.abc.com/prefix or http://www.abc.com/prefix/ causing 404
  • .

    5. Ask for advice

    1. what"s wrong with my method if I use regular matching "non-dist is not empty"?
    2. or are there any other ways to address this requirement?
    May.28,2022

    because your third location expression happens to match http://www.abc.com/prefix/index.html.

    therefore, you only need to exclude the address after the first location jump from the third location, such as

    - location ~* ^\/prefix/(?!(dist)).+$ {
    + location ~* ^\/prefix/(?!(dist|index\.html)).+$ {
    < H2 > reference < / H2 >

    nginx location testing tools
    https://nginx.viraptor.info/

    Menu