nginx proxy_pass 404错误,不明白为什么

我试图将所有的/ api调用传递给我的web服务,但我一直使用以下configuration获取404s。 按预期调用/返回index.html。 有谁知道为什么?

upstream backend{ server localhost:8080; } server { location /api { proxy_pass http://backend; } location / { root /html/dir; } } 

更多信息在这里

 adept@HogWarts:/etc/nginx/sites-available$ curl -i localhost/api/authentication/check/user/email HTTP/1.1 404 Not Found Server: nginx/1.2.1 Date: Mon, 22 Apr 2013 22:49:03 GMT Content-Length: 0 Connection: keep-alive adept@HogWarts:/etc/nginx/sites-available$ curl -i localhost:8080/authentication/check/user/email HTTP/1.1 200 OK Content-Type: application/json Date: Mon, 22 Apr 2013 22:49:20 GMT Transfer-Encoding: chunked {"user":["false"],"emailAddress":["false"]} 

这个

 location /api { proxy_pass http://backend; } 

需要这个

 location /api/ { proxy_pass http://backend/; } 

由于某种原因,Nginx 1.6.2中的proxy_pass会在传递给上游之前剪切头“Host”,并请求默认服务器的捕获,甚至proxy_header_pass也无济于事,所以我必须明确地设置它:

 location / { proxy_set_header Host $host; proxy_pass http://backend; } 

我忘了听80号港口,修好了。

nginx配置的“http”部分,位于:/etc/nginx/nginx.conf,如下所示:

 http { server { listen 192.111.111.11:80; location /path1/ { proxy_pass http://127.0.0.1:3000/path1/ } } } 

*注意:用下面的IP地址替换192.111.111.11。 运行“ifconfig”命令,“inet addr”部分会给你的IP地址

现在,访问
http://192.111.111.11/path1/
会得到访问的结果
http://127.0.0.1:3000/path1/