我需要 NGINX 将某个目录代理到外部 S3 存储桶,我这样做是这样的:
location ~ ^/logos/(.*)$ {
proxy_pass https://s3-us-west-2.amazonaws.com/mybucket/logos/$1;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
}
我还需要所有其他 URI 来转到通配符 CGI 脚本。我这样做:
location ~ \.cgi$ {
include fcgiwrap.conf;
}
rewrite ^ /myscript.cgi;
问题是,当我将两者放在同一个 server {} 声明中时,它们似乎互相排斥。要么 /logos/* 下的所有内容都会路由到 CGI 脚本,要么 CGI 脚本会得到 404。
答案1
是的,这个办法奏效了:
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;
}
}