I have the following configuration for a swagger.json in nginx:
location /project1/v2 {
absolute_redirect off;
alias /project1/v2;
expires 1d;
location ~* .(?:json|yml|yaml)$ {
# SWAGGER_ROOT
expires -1;
include /etc/nginx/templates/cors.conf;
}
include /etc/nginx/templates/cors.conf;
}
location /project1{
set $args $args&url=http://localhost/project1/v2/swagger.json;
absolute_redirect off;
alias /usr/share/nginx/html/;
expires 1d;
include /etc/nginx/templates/cors.conf;
}
and this works fine. However, I have a second project where I try to capture the name from URL using regex and redirect as follows:
location ~ ^/(project1|project2)/v2 {
absolute_redirect off;
alias /$1/v2;
expires 1d;
location ~* .(?:json|yml|yaml)$ {
# SWAGGER_ROOT
expires -1;
include /etc/nginx/templates/cors.conf;
}
include /etc/nginx/templates/cors.conf;
}
location ~ ^/(project1|project2) {
set $args $args&url=http://localhost/$1/v2/swagger.json;
absolute_redirect off;
alias /usr/share/nginx/html/;
expires 1d;
include /etc/nginx/templates/cors.conf;
}
and this yields to too many redirects error with URL changing to: http://localhost/project1/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/?&url=http://localhost/project1/v2/swagger.json&url=http://localhost/project1/v2/swagger.json&url=http://localhost/project1/v2/swagger.json&url=http://localhost/project1/v2/swagger.json&url=http://localhost/project1/v2/swagger.json...
What am I missing?