How do I proxy pass a URL in Nginx where location match is a URL and proxy pass has another URL
Have you tried simple?
location = /super-shots.xml {
proxy_pass http://mybucket.s3.amazonaws.com/depth0/depth1/depth2/sitemap.xml;
}
You don't need anything on local file system.
Your problem is that request /super-shot.xml
matches location ~* \.(js|ico|...xml...
.
Using =
suffix we tell nginx that this exact request should be processed here and it must not look for other possible matching locations.
Related videos on Youtube
anup
Updated on September 18, 2022Comments
-
anup almost 2 years
We have hosted some xml files in a S3 bucket on Amazon AWS. The web server is powered by Nginx. For a particular URL matching '/super-shots.xml' , Nginx must proxy pass through S3 location which is : http://mybucket.s3.amazonaws.com/depth0/depth1/depth2/sitemap.xml
What I want is this (Nginx Config):
location ~* /super-shots.xml { proxy_pass http://mybucket.s3.amazonaws.com/depth0/depth1/depth2/sitemap.xml; }
Result is an error:
nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block
If I do not do a regular expression match (~*|~), then there is no syntax errors, but the page returns 404. Note that the file does not exists on system path.
I have tried looking around for solution, but most of deal with path as a match. How do I work around this?
For now, I have done a path based proxy-pass which works (given below). But, I want it with the URL match.
#Nginx Config: location /super-shots { proxy_pass http://mybucket.s3.amazonaws.com/depth0/depth1/depth2/sitemap.xml; } # On file system : Empty directory mkdir $docroot/depth0/depth1/depth2/ nginx -s reload
Update 1: Based on Alexey Ten's comment. Sample of the Nginx Configuration can be found here
-
anup over 8 yearsI tried that. The page is 404 (server : nginx) ! It doesn't proxy_pass at all.
-
Alexey Ten over 8 years@anup then you must show full nginx config
-
anup over 8 yearsA sample configuration file can be found here: paste.ubuntu.com/15000876 I had to alter domain name and remove rewrite rules (I assure that no rewrite rules matches the one in question). Nginx -- version: nginx/1.4.5
-
Alexey Ten over 8 yearsPut it into your post
-
anup over 8 yearsArgh ! Such a silly miss ! Thanks a ton @alexey-ten