I wish that every request in the following format: /files/(whatever..)/(1 or 2 or 3) will go to the files_1 upstream with the /(whatevet) command. If the url is in the following format /files/(whatever..)/(4 or 5 or 6), it will go to the files_2 upstream with the /(whatevet) command.
Here is my location file:
location ~ "^/files/(.*)/[123]/" { rewrite ^/files/(.*)/(.*) /$1 break; proxy_pass http://files_1 ; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; } location ~ "^/files/(.*)/[456]/" { rewrite ^/files/(.*)/(.*) /$1 break; proxy_pass http://files_2 ; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; } When I check the logs, It doesn't do the redirection with the command /files/save/2/ (which should go to files_1 upstream with the command: /save)
How can I do it?
locationregex requires a trailing/after the final numeric element. So/files/save/2does not match any of the above location blocks. Also, yourrewriteregex is not guaranteed to pick out only thesavefor the$1.