我希望我的所有图像(jpg | gif | png)目前从mydomain.com/files/被服务器从我从static.mydomain.com设置到服务器文件的第二台机器上被切断。
谢谢
您可以使用代理传递: http : //wiki.nginx.org/HttpProxyModule#proxy_pass
在你的情况下,这可能是这样的:
location /mydomain.com/files/.*\.(jpg|gif|png) { proxy_pass http://static.mydomain.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
请注意,minniux的解决scheme不是重写,但会导致所有stream量通过“redirect”主机。 这不是我想要的。
改用rewrite指令:
location /files/.*\.(jpg|gif|png) { rewrite ^/(.*)$ "$scheme://static.mydomain.com/$1" permanent; }
您不需要使rewrite的正则expression式更复杂; location块已经只影响匹配的请求。
$schemevariables允许您根据原始schemeredirect到https或http 。
PS:redirect也将X-Forwarded-*在静态服务器上关心X-Forwarded-*头字段的痛苦。