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

1 Answer 1


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.

  • I tried that. The page is 404 (server : nginx) ! It doesn't proxy_pass at all.
    – anup
    Commented Feb 9, 2016 at 8:49
  • @anup then you must show full nginx config
    – Alexey Ten
    Commented Feb 9, 2016 at 8:49
  • A 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
    – anup
    Commented Feb 9, 2016 at 9:19
  • Put it into your post
    – Alexey Ten
    Commented Feb 9, 2016 at 9:55
  • I updated answer
    – Alexey Ten
    Commented Feb 9, 2016 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .