nginx configured as loadbalancer returning 404 not found
Sergey A. Osokin
osa at freebsd.org.ru
Fri May 17 14:09:03 UTC 2024
Hi Kaushal,
On Fri, May 17, 2024 at 04:49:59PM +0530, Kaushal Shriyan wrote:
>
> I am running nginx version 1.26 on "Ubuntu 22.04.4 LTS" I have configured
> the nginx as load balancer and the configuration details are as follows
>
> # nginx -v
> nginx version: nginx/1.26.0
> #
>
> server {
[...]
>
> location / {
> # Define the upstream servers for load balancing
> proxy_pass http://backend/;
Could you please explain a reason why did you decide to use `/' after
the backend's name in the proxy_pass directive.
> # Set HTTP headers
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header X-Forwarded-Proto $scheme;
> }
>
> location /api/docs/ {
> proxy_pass http://backend/api/docs/;
It seems like '/api/docs/' can be safely removed, so
I'd recommend to read the documentation for the proxy_pass directive, [1]
<quote>
If proxy_pass is specified without a URI, the request URI is passed to the
server in the same form as sent by a client when the original request is
processed, or the full normalized request URI is passed when processing
the changed URI:
location /some/path/ {
proxy_pass http://127.0.0.1;
}
</quote>
[...]
> When i hit http://tead-local.com:80/api/docs/ I get http 200 response from
> the backend server whereas when I try to hit using public IP :-
> http://210.11.1.110:8085/api/docs/ I encounter http 404 not found.
>
> 101.0.62.200 - - [17/May/2024:16:38:24 +0530] "GET /api/docs/ HTTP/1.1" 404
> 153 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)
> AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15
> Ddg/17.5" "-"
To see the whole picture of processing a request by nginx, I'd
also recommend to enable a debugging log, [2].
Hope that helps.
References
----------
1. https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
2. https://nginx.org/en/docs/debugging_log.html
--
Sergey A. Osokin
More information about the nginx
mailing list