2013-03-16 15 views
14

私のウェブサイトを正しく表示するために、このエイリアスをnginxに設定するのに苦労しています。このエイリアス設定で拡張子を表示せずにnginxでhtmlファイルを提供する方法

私が関係するウェブサイトは、mywebsite.com/mrからアクセス可能であり、mywebsite.com/にあるサイトとは異なっている必要があります。

  1. /fullpath/index.htmlにあるインデックスファイル:ウェブサイトは、サイトには、コンテンツの3種類のサービスを提供する必要があります(簡単にするために短縮)/fullpathに位置しています。
  2. その他のhtmlファイル(ブラウザに.htmlの拡張子は表示されません)。
  3. /fullpathとサブディレクトリにある静的アセット(js/css/img)。

私はtry_filesにマッチのための周りに変更しようと、彼らはすべてがちょうどいないと同時に、勤務状況見つけた:

location /mr { 
    default_type "text/html"; 
    alias /fullpath; 

    # with this one 1 and 3 work 
    # try_files $uri/index.html $uri.html $uri; 

    # with this one 2 and 3 work 
    # try_files $uri $uri.html $uri/index.html; 

    # with this one 1 and 2 work 
    try_files $uri.html $uri/index.html $uri; 
} 

1がそれ404の動作しません。誰も私がどのようにすべての種類のファイルを正しく提供できるかを知っていますか?

答えて

19

明らかにエイリアスとtry_files don't work together。しかし、エイリアスを使う必要はないと思います。

  • 正確なファイルを:しようとするだろう

    location /mr { 
        default_type "text/html"; 
        try_files /fullpath/$uri /fullpath/$uri.html /fullpath/$uri/index.html /fullpath/index.html; 
    } 
    

  • .htmlが追加されたファイル。
  • パスのインデックス。
  • デフォルトのインデックス。

私はrootディレクティブがtryファイルで動作しますが、テストできないと思います。

server{ 
    location /mr { 

     root /home/mysite/fullpath; 

     default_type "text/html"; 
     try_files $uri $uri.html $uri/index.html index.html; 
    } 
} 
5

私は@Danackは(直接htmlファイルをサーブ)私が探していたところに私を導いた掲載内容のコンボを使用:

location /health-check { 
    default_type "text/html"; 
    alias /path/to/my/file.html; 
} 
+1

はありがとうを。完璧に動作します。 –

関連する問題