2011-12-08 3 views
10

現在、httpで自分のサイトを実行しており、nginxがリダイレクトを自動的に処理するようにhttpsに移動します。これはかなり簡単です。1つのファイルを除き、すべてのhttpをnginxのhttpsにリダイレクトします。

しかし、(いくつかの理由で)他のサイトからホットリンクされているファイルがあります。そのうちのいくつかはhttpを超え、httpsを超えています。私は、ファイルがhttpとhttpsの両方で利用できるようにして、ブラウザーが「混合コンテンツ」ダイアログに不満を寄せないようにします。

HTTP(S):

だから、nginxのルールが言うべき[some_sha1_hash] //mydomain.com/scripts/ /file.js:ファイルのパスは次のようになります「要求した場合それ以外の場合は、httpからhttpsへのすべてのリクエストをリダイレクトします。ただし、この1つのファイルがリクエストされている場合を除き、http-> httpsリダイレクトは行われません。

誰でもこのような設定について学ぶためにどこに向かうか、設定自体を助けてくれますか?前もって感謝します。 (申し訳ありませんが、私はnginxの設定でまだ十分習熟していないよ。)

答えて

-2
server { 
    listen   80; 
    server_name my.domain.com; 
    rewrite  ^https://$server_name$request_uri? permanent; 
} 

server { 
    listen   443; 
    server_name my.domain.com; 

    ssl   on; 

    [....] 
} 

+3

これは除外したい1つのファイルを除外するようには見えません。または私は間違っていますか? –

+0

'location'ブロックにロジックを含まないソリューションの場合+1。 – orokusaki

3

はこのお試しくださいイム間違っていない場合は、上記の大部分は、トリックを行う必要があります。

server { 
    listen 80; ssl off; 
    listen 443 ssl; 
    server_name example.com; 

    # <ssl settings> 
    # ... other settings 

    location = /scripts/[some_sha1_hash]/file.js { 
    # Empty block catches the match but does nothing with it 
    } 

    location/{ 
    if ($scheme = "http") { 
     rewrite^https://$http_host$request_uri? permanent; 
    } 

    # ... other settings 
    } 
} 
5

これはどの作品、私がやったことです:この1だけのHTTPリクエストを処理したファイルを用意しています

server { 
    listen 80; 
    server_name example.com; 
    charset  utf-8; 
    access_log /var/www/path/logs/nginx_access.log; 
    error_log /var/www/path/logs/nginx_error.log; 

    location /path/to/script.js { 
      # serve the file here 
    } 
    location/{ 
     return 301 https://example.com$request_uri; 
    } 
} 

- それ以外の場合は赤httpsに転送されます。すべてのhttps要求を処理するsslサーバーブロックを定義します。

server { 
    listen   443; 
    server_name example.com; 

    ssl   on; 

    # rest of the config 
} 

このようにして、スクリプトファイルはhttpとhttpsで利用できるようになります。