I'm 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

  • Is the 404 coming from nginx or from the backend? Commented Apr 22, 2013 at 22:51
  • My understanding is its coming form nginx, I put some more info in the question to help.
    – Roge
    Commented Apr 22, 2013 at 22:53
  • done chown -R on /html/dir? Commented Apr 22, 2013 at 22:59
  • No, but there is no problem with the / location; calls to localhost return index.html from /html/dir as expected the problem is with the /api/ location
    – Roge
    Commented Apr 22, 2013 at 23:00
  • location /api { proxy_pass backend; } Needs to be this location /api/ { proxy_pass backend; }
    – Roge
    Commented Apr 22, 2013 at 23:45

1 Answer 1


I think you're missing a slash in your proxy_pass, see http://nginx.org/r/proxy_pass.

It should be proxy_pass http://backend/;, if you want to map /api locationfrom Nginx to / from upstream, otherwise, it'll be going to /api on upstream, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.