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

标签 nginx

我正在尝试将所有对/api 的调用传递给我的网络服务,但使用以下配置我不断收到 404。按预期调用/返回 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 proxy_pass 404 错误,不明白为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16157893/

相关文章:

php - 在 Nginx 设置页面上安装 Magento 2.0.2 不起作用

ssl - 生产中的 Rails 5 action cable cable SSL - WebSocket 连接失败 : Error during WebSocket handshake: Unexpected response 301

node.js - Nginx proxy_pass 在端口 80 上不起作用

PHP 上传的文件超过php.ini中的upload_max_filesize指令

perl - 同一个 nginx 虚拟主机中的几个 (fastcgi/uwsgi/scgi/proxy_pass) Mojolicious 应用程序的示例?

java.lang.IllegalArgumentException : The character [_] is never valid in a domain name

ruby-on-rails - Nginx 错误 : client intended to send too large body

mysql - uWsgi 的响应丢失

nginx 502 阻碍 eb Worker 和 SQS 导致可见性超时不被遵守

nginx - 通过 http 进行 RTMP 流式传输