I am using NGINX to proxy_pass
all requests with prefix /auth/
to a nodejs api server at localhost:3000
.
I have this single config file /etc/nginx/sites-enabled/default3.conf
:
server {
location /auth/ {
rewrite /auth/(.+) /$1 break;
proxy_pass http://127.0.0.1:3000;
proxy_redirect off;
proxy_set_header HOST $host;
}
}
It works fine for most of my requests (instead of GET http://localhost:3000/logout
, GET http://localhost/auth/logout
would work as expected), except this request GET http://localhost/auth/docs
, which should map to http://localhost:3000/docs
but I got a redirect:
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 15 Dec 2021 01:59:02 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 175
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Security-Policy: default-src 'none'
X-Content-Type-Options: nosniff
Location: /docs/
then a 404 NOT FOUND instead:
HTTP/1.1 404 Not Found
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 15 Dec 2021 03:20:26 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Content-Encoding: gzip
It seems like when I GET http://localhost/auth/docs
, the request hit my nodejs server, but then got redirected back to http://localhost/docs
, but how could this be possible? I still can GET http://localhost:3000/docs
without a problem.
UPDATED
http://localhost:3000/docs
is where I am serving Swagger UI for the server API, using the npm module swagger-ui-express
.