Nginx 将子路径重定向到根 url

时间:2021-03-15 15:33:02

标签: nginx url-rewriting

我在定义 nginx 规则时遇到了一些问题

当我访问 localhost:3000 时,我需要获取 index.html 但是,当我得到 localhost:3000/dummy/folder/assetA.js 我希望它也能工作。 根据我的设置,第二部分不起作用。 我的正则表达式有问题还是重写不是最好的选择?

- var/www
  - innerFolderA
  - innerFolderB
  - index.html
  - assetA.js
  - assetB.js
http {
    server {
        # listen on port 3000
        listen 3000;
        # save logs here
        access_log /var/log/nginx/access.log compression;

        # where the root here
        root /var/www;
        # what file to server as index
        index index.html index.htm;

        location / {
            try_files $uri $uri/ /index.html;
        }
        
        location /dummy/folder {
            rewrite ^(\/dummy\/folder\/)(.*)$ \/$2 break;
        }
    }
}

0 个答案:

没有答案