我正在将nginx配置为反向代理,下面是我的配置文件。我想将到达nginx服务器(abc.com)的请求代理到域example.com,例如abc.com/api/hello ---> example.com/api/hello。这样做的主要原因是避免对example.com进行身份验证。以下代码段适用于我当前的用例。
但是现在有一个用例,我的nginx必须为到达路径“ /”的请求返回HTTP 404。有人可以指导如何处理HTTP 404和反向代理条件吗?
server{
listen 80;
root public;
index index.html index.htm Default.htm;
location /health
{
root data;
index index.html index.htm Default.htm;
}
location / {
proxy_pass https://example.com/;
proxy_set_header Cookie "";
proxy_set_header Authorization "";
proxy_set_header xxxxxxxxx "true";
proxy_hide_header Cookie;
}
}
答案 0 :(得分:0)
将此添加为第一个位置块
location = / {
return 404;
}