nginx错误\u页面转发而不是重定向

nginx错误\u页面转发而不是重定向,nginx,single-page-application,Nginx,Single Page Application,我有一个nginx作为反向代理,它做一些proxy\u传递的事情。代理位于一个角度SPA前面,启用了HTML5路由,周围还有其他难看的东西,因此我无法处理服务器上的404,该服务器提供页面 目前,我有以下配置: worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream;

我有一个nginx作为反向代理,它做一些
proxy\u传递
的事情。代理位于一个角度SPA前面,启用了HTML5路由,周围还有其他难看的东西,因此我无法处理服务器上的404,该服务器提供页面

目前,我有以下配置:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    server {
        listen  3000;
        location /int {
            proxy_pass http://localhost:9131/int;
            proxy_set_header X-Forwarded-For "127.0.0.1";
        }
        location /app/static {
            proxy_pass http://localhost:9131/int/static;
            proxy_set_header X-Forwarded-For "127.0.0.1";
        }
        location /app/api {
            proxy_pass http://localhost:9131/int/api;
            proxy_set_header X-Forwarded-For "127.0.0.1";
        }

        location / {
            proxy_set_header Accept-Encoding "";
            proxy_pass https://example.com/;
            sub_filter 'https://example.com/int' 'http://$host:$server_port/int';
            sub_filter '<base />' '<base href="/app/" />';  
            proxy_intercept_errors on;
            error_page 404 = @fallback;
        }

        # EDIT: after comment, but got the following Error: 
        #   "proxy_pass" cannot have URI part in location given by regular
        #   expression, or inside named location, or inside "if" statement, 
        #   or inside "limit_except" block in ...\nginx-1.14.2/conf
        #   /nginx.conf:37
        location @fallback {
            proxy_pass http://localhost:3000/app;
        }
    }
}

worker\u进程1;
事件{
工人(1024);;
}
http{
包括mime.types;
默认_类型应用程序/八位字节流;
发送文件到;
服务器{
听3000;
位置/内部{
代理通行证http://localhost:9131/int;
“127.0.0.1”的代理集标题X-转发;
}
位置/应用程序/静态{
代理通行证http://localhost:9131/int/static;
“127.0.0.1”的代理集标题X-转发;
}
位置/应用程序/api{
代理通行证http://localhost:9131/int/api;
“127.0.0.1”的代理集标题X-转发;
}
地点/{
代理集头接受编码“”;
代理通行证https://example.com/;
子过滤器'https://example.com/int“”http://$host:$server_port/int';
子过滤器“”;
上的代理截获错误;
错误\u第404页=@回退;
}
#编辑:在注释之后,但出现以下错误:
#“proxy_pass”在正则表达式给定的位置不能有URI部分
#表达式,或在命名位置内,或在“if”语句内,
#或位于…\nginx-1.14.2/conf中的“限制\u除外”块内
#/nginx.conf:37
位置@fallback{
代理通行证http://localhost:3000/app;
}
}
}
当我转到
example.com/app/foobar
时,我被重定向到
example.com/app
。我想要的是转发,这样我就可以在不修改URL或状态码的情况下获得
example.com/app
的内容。然后SPA可以处理路由

编辑:
添加了名为location(
@fallback
})的配置

提供了一些选项。名为
的location
看起来可能适合您。感谢您的提示。我已经找到了它,但随后我收到了以下错误消息:“proxy\u pass”URI部分不能位于正则表达式给定的位置,或位于命名位置内,或位于“if”语句内,或位于“limit_except”内在…\nginx-1.14.2/conf/nginx.conf:37中阻塞如果要重写URI,请使用
rewrite…break
-尝试从
proxy\u pass
语句中删除
/app
部分并添加
rewrite^(.*)$/app$1 break;
提供了一些选项。命名的
位置看起来可能适合您。感谢您的提示。我已经找到了该位置,但随后我收到了以下错误消息:“proxy\u pass”不能在正则表达式给定的位置中,或在命名位置中,或在“if”语句中,或在“…\nginx-1.14.2/conf/nginx.conf:37”中的“limit_except”块如果要重写URI,请使用
rewrite…break
-尝试从
proxy_pass
语句中删除
/app
部分,并添加
rewrite^(.*)$/app 1 break;