nginx将虚拟目录重写为文件 [英] nginx rewrite virtual directory to file
问题描述
这应该很容易做到,但是我的头撞在墙上了.如果我收到www.mysite.com/mypath的请求,则希望提供www.mysite.com/myotherpath/thisfile.html的内容.如何使用Nginx配置做到这一点.
This should be really easy to do but I'm hitting my head on the wall. If I get a request for www.mysite.com/mypath I want to serve the content of www.mysite.com/myotherpath/thisfile.html. How can I do this with an nginx config.
推荐答案
在适当的位置块内使用重写指令.因此,例如,您拥有可以处理所有请求的基本位置
Use rewrite directive within proper location block. So for example you have basic location which will handle all requests
location / {
/*your rules here*/
}
您将需要添加另一个块,这将为您处理特定路径
You will need to add another block, which will do for you handling of specific path
location /mypath {
rewrite ^/mypath$ /real/path/to/file/thisfile.html;
}
还可以让您的服务器在该块中认为thisfile.html
是默认设置,您可以使用try thisfile.html
指令
Also for your server to think in that block that thisfile.html
is default you can use try thisfile.html
directive
在官方页面 Nginx官方RewriteModule官方页面
这篇关于nginx将虚拟目录重写为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!