我正在尝试让我的 nginx 反向代理传递给 2 个 apache 网络服务器中的 1 个。但是我的设置有问题。当我想连接到“localhost/central/api”时,它只有在我转到“localhost/central/api/”(尾部斜线)时才有效。 否则 url 将再次更改为“localhost/central/”。
需要/想要这个似乎很奇怪,我不知道如何解决这个问题。 它似乎不是由 apache 应用程序引起的。 我不想需要最后一个尾部斜杠,我也不希望 nginx 在传递给我的 apache 服务时将它添加到 url 的末尾。
这是我的 nginx 配置文件的相关部分。
server {
listen 80;
server_name localhost;
location ^~ /central {
proxy_pass http://central/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location ^~ /microservices {
proxy_pass http://microservices/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
尝试使用重写规则代替,但这也没有解决它。