我正在使用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/
。
卷曲:
* 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服务器?