nginx rewrite virtual directory to file

痞子三分冷 提交于 2019-12-03 11:32:07
Alexey Kamenskiy

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; 
}

Also for your server to think in that block that thisfile.html is default you can use try thisfile.html directive

It is all well explained on official page Official Nginx RewriteModule page

location = /mypath {
    try_files /myotherpath/thisfile.html =404;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!