13

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.

4

2 に答える 2

14
location = /mypath {
    try_files /myotherpath/thisfile.html =404;
}
于 2012-09-10T20:00:24.633 に答える
10

適切なロケーションブロック内でrewriteディレクティブを使用します。たとえば、すべてのリクエストを処理する基本的な場所があります

location / {
    /*your rules here*/
}

別のブロックを追加する必要があります。これにより、特定のパスを処理できます。

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

また、サーバーがデフォルトであるそのブロックで考えるために、ディレクティブthisfile.htmlを使用できますtry thisfile.html

それはすべて公式ページでよく説明されています公式NginxRewriteModuleページ

于 2012-09-09T19:03:59.610 に答える