Я обслуживаю свои статические страницы, используя nginx
.
Я пытаюсь прокси-запросы от /api
к моему бэкэнд-сервису.
nginx:
server {
listen 0.0.0.0:5000;
auth_basic "Administrator’s Area";
auth_basic_user_file /.../.htpasswd;
root /app;
index index.htm index.html;
location / {
try_files $uri /index.html;
}
location /api/ {
proxy_pass https://api.example.com/;
}
location /health {
auth_basic off;
return 200;
}
}
Открытие браузера и отправка запроса (от js
) приводит к перенаправлению на http://localhost:5000/api/
.
curl:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.14.0
< Date: Wed, 17 Oct 2018 21:59:43 GMT
< Content-Type: text/html
< Content-Length: 185
< Location: http://localhost:5000/api/
< Connection: keep-alive
< X-Frame-Options: SAMEORIGIN
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>
Почему nginx
возвращает перенаправление вместо прокси-запроса на удаленный API-сервер?