nginx重写虚拟目录到文件

这应该很容易做到,但我正在把我的头撞在墙上。 如果我收到www.mysite.com/mypath的请求,我想要提供www.mysite.com/myotherpath/thisfile.html的内容。 我怎么能用一个nginxconfiguration来做到这一点。

在适当的位置块内使用重写指令。 所以例如你有基本的位置,将处理所有的请求

location / { /*your rules here*/ } 

您将需要添加另一个块,这将为您处理特定的路径

 location /mypath { rewrite ^/mypath$ /real/path/to/file/thisfile.html; } 

此外,为了让你的服​​务器在该块认为thisfile.html是默认的,你可以使用try thisfile.html指令

在官方网页官方的Nginx Rewritemodulee页面上都有很好的解释

 location = /mypath { try_files /myotherpath/thisfile.html =404; }