我已经search了一段时间这样做的正确方法。
在https服务器上请求不存在的文件时,redirect到http服务器并请求相同的文件。
例如。
https:// example.org/some_missing_file.html – redirect – > http:// example.org/some_missing_file.html
https:// example.org/existing_file.html – 提供文件
https:// example.org/SomeDir/missing_file – redirect – > http:// example.org/SomeDir/missing_file
https:// example.org/SomeMissingDir/ – redirect – > http:// example.org/SomeMissingDir/missing_file
这如果基于片段的作品
listen 443 ssl; #... more config if (!-e $request_filename) { rewrite ^ http:// example.org$request_uri permanent; break; }
但是“如果是邪恶” – http://wiki.nginx.org/IfIsEvil
所以这是我试图在try_files版本 – 这是行不通的。
try_files $uri @redirect; location @redirect { rewrite ^ http:// example.org$request_uri permanent; break; }
我已经尝试了很多变化。 proxy_redirects,返回302's – 当文件位于子目录中时,它们无法redirect或不工作,或者如果为空,则不redirect根目录。
有没有人有一个防弹的基于try_files的替代?
(由于链接检查器不知道example.org,ps空间!)
server { listen 443 ssl; root /path/to/documents; location / { try_files $uri @redirect; } location @redirect { return 301 http://example.org$request_uri; } }