1

trying to pass off all calls to /api to my webservice but I keep getting 404s with the following config. Calls to / return index.html as expected. Does anyone know why ?

    upstream backend{
server localhost:8080;
}

 server {

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

        location / {

        root /html/dir;
        }

 }

More info here

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"]}
1
  • location /api { proxy_pass backend; } Needs to be this location /api/ { proxy_pass backend; }
    – Roge
    Apr 22, 2013 at 23:44

1 Answer 1

1

error 404 returns your backend, he does not know anything about the url /api, which is transferred to it by proxy_pass directive.

curl -i localhost/api/authentication/check/user/email passed backend as /api/authentication/... instead of /authentication/...

If proxy_pass is specified without URI, a request URI is passed to the server in the same form as sent by a client when processing an original request

Try (note slash / after backend)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .