我需要在上游服务器上重定向输入错误的API请求。 我正在尝试将请求从localhost:1337 / streaminfo重定向到localhost:1337 / streaminfos。 这是我下面的配置。当我将其移到上游的前端时,重定向工作正常,但在CMS上却没有。
upstream frontend {
server frontend:3000;
}
upstream cms {
server cms:1337;
}
upstream backend {
server backend:4000;
}
server {
listen 80;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Accept-Encoding "";
location / {
proxy_pass http://frontend/;
proxy_redirect default;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /api/ {
proxy_pass http://backend/;
proxy_redirect default;
}
}
server {
listen 81;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Accept-Encoding "";
client_max_body_size 100M;
location /streaminfo {
rewrite ^/streaminfo /streaminfos redirect;
proxy_pass http://cms/;
proxy_redirect default;
}
location / {
proxy_pass http://cms/;
proxy_redirect default;
}