nginx proxy_pass 404 error, don't understand why

前端 未结 4 2162
梦毁少年i
梦毁少年i 2020-12-08 06:26

I am 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?

4条回答
  •  执念已碎
    2020-12-08 06:58

    Just want to remind others that the slash(backend*/*) after your proxy_pass url is very important!

    if the config is

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

    and you visit http://abc.xyz/api/endpoint, you would be direct to http://backend/api/endpoint;

    if the config is

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

    and you visit http://abc.xyz/api/endpoint, you would be directed to http://backend/endpoint.

    That's the difference.

    For more, refer to: Nginx reverse proxy return 404

提交回复
热议问题