0

I need NGINX to proxy a certain directory to an external S3 bucket, which I'm doing like so:

   location ~ ^/logos/(.*)$ {
          proxy_pass           https://s3-us-west-2.amazonaws.com/mybucket/logos/$1;
          proxy_set_header     X-Forwarded-For $http_x_forwarded_for;
   }

I also need all other URIs to go to a wildcard CGI script. I'm doing like this:

   location ~ \.cgi$  {
            include         fcgiwrap.conf;
    }
    rewrite ^ /myscript.cgi;

The problem is, when I put both in the same server {} declaration, they seem to be mutually exclusive. Either everything under /logos/* gets routed to the CGI script, or the CGI script gets a 404.

1
  • You may need to wrap the rewrite statement inside a location / { ... } block. – Richard Smith Mar 28 '20 at 8:31
0

Yep that did the trick:

server { 
    listen      80;
    server_name myserver.mydomain.com *.mydomain.com;
    location ~ ^/logos/(.*)$ {
        proxy_pass             https://s3-us-west-2.amazonaws.com/mybucket/logos/$1;
        proxy_set_header       X-Forwarded-For $http_x_forwarded_for;
    }
    location ~ \.cgi$  {
        include                fcgiwrap.conf;
    }
    location / {
        rewrite                ^ /myscript.cgi;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.