nginx-提供不同路线的水疗服务

nginx-提供不同路线的水疗服务,nginx,Nginx,我在/usr/app/build中有一个包。它有一个index.html 我想: 从/usr/app/build向/build发出的请求 由/usr/app/build/index.html响应的任何其他请求 就这样 下面的选项不起作用(给出404)。将try_files参数替换为/build/index.html,也没有/index.html的显式位置和/index.html的try_files参数 location /build { alias /usr/app/build; }

我在/usr/app/build中有一个包。它有一个index.html

我想:

  • 从/usr/app/build向/build发出的请求
  • 由/usr/app/build/index.html响应的任何其他请求
  • 就这样

    下面的选项不起作用(给出404)。将
    try_files
    参数替换为
    /build/index.html
    ,也没有
    /index.html
    的显式位置和
    /index.html
    try_files
    参数

    location /build {
        alias /usr/app/build;
    }
    
    location / {
        try_files /usr/app/build/index.html =404;
    }
    

    我很困惑。如何实现这一点?

    提供文件的任何位置都必须具有
    根目录
    别名
    ,或从周围块继承值。在您的情况下,
    root
    alias
    更有效(有关详细信息,请参阅)

    try\u files
    语句的file元素被附加到
    root
    值以生成返回文件的路径名。有关详细信息,请参阅

    例如:

    root /usr/app;
    location /build {}
    location / {
        try_files /build/index.html =404;
    }
    
    root /usr/app;
    location / {
        try_files $uri $uri/ /build/index.html;
    }
    

    如果
    /usr/app/build/index.html
    始终存在,则
    =404
    在很大程度上是多余的。通常会将默认操作放在
    try\u files
    语句的末尾,例如:

    root /usr/app;
    location /build {}
    location / {
        try_files /build/index.html =404;
    }
    
    root /usr/app;
    location / {
        try_files $uri $uri/ /build/index.html;
    }
    
    但上述规定并不符合“任何其他要求”的确切要求