簡體   English   中英

nginx將虛擬目錄重寫為文件

[英]nginx rewrite virtual directory to file

這應該真的很容易做到,但是我的頭撞在牆上。 如果我收到www.mysite.com/mypath的請求,則希望提供www.mysite.com/myotherpath/thisfile.html的內容。 我該如何使用Nginx配置。

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

在適當的位置塊內使用重寫指令。 因此,例如,您擁有可以處理所有請求的基本位置

location / {
    /*your rules here*/
}

您將需要添加另一個塊,這將為您處理特定路徑

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

同樣,為了讓您的服務器在該塊中認為thisfile.html是默認設置,您可以使用try thisfile.html指令

官方頁面上對此都有很好的解釋官方Nginx RewriteModule頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM