5

I am not sure if this exactly qualifies for StackOverflow, but since I need to do this programatically, and I figure lots of people on SO use CloudFront, I think it does... so here goes:

I want to hide public access to my custom origin server.

CloudFront pulls from the custom origin, however I cannot find documentation or any sort of example on preventing direct requests from users to my origin when proxied behind CloudFront unless my origin is S3... which isn't the case with a custom origin.

What technique can I use to identify/authenticate that a request is being proxied through CloudFront instead of being directly requested by the client?

The CloudFront documentation only covers this case when used with an S3 origin. The AWS forum post that lists CloudFront's IP addresses has a disclaimer that the list is not guaranteed to be current and should not be relied upon. See https://forums.aws.amazon.com/ann.jspa?annID=910

I assume that anyone using CloudFront has some sort of way to hide their custom origin from direct requests / crawlers. I would appreciate any sort of tip to get me started. Thanks.

4

3 に答える 3

0

CloudFront のみが使用するカスタム CNAME を作成します。独自のサーバーで、その CNAME から来ていない静的アセットのリクエストをブロックします。

たとえば、サイトがhttp://abc.mydomain.netの場合、まったく同じ場所を指すhttp://xyz.mydomain.netの CNAME をセットアップし、その新しいドメインをオリジン プル サーバーとして CloudFront に配置します。 . 次に、リクエストに応じて、それが CloudFront からのものかどうかを判断し、必要なことを行うことができます。

欠点は、これがあいまいさによるセキュリティであることです。クライアントはhttp://xyzy.mydomain.netへのリクエストを決して見ませんが、それを理解する方法がないわけではありません。

于 2014-02-09T23:09:02.347 に答える
0

すべてのクローラーが Web サイトのすべての機密コンテンツにアクセスするのを防ぐために、Facebook の robots.txt に似たものを使用することをお勧めします。

https://www.facebook.com/robots.txt (少し調整する必要があるかもしれません)

その後、アプリケーション (Rails など) をカスタム オリジン サーバーに指定するだけです。

サイトのすべての URL を次のような絶対 URL に書き換えます。

https://d2d3cu3tt4cei5.cloudfront.net/hello.html

基本的に、すべての URL はクラウドフロント ディストリビューションを指す必要があります。誰かがhttps://d2d3cu3tt4cei5.cloudfront.net/hello.htmlからファイルを要求し、 hello.html がない場合、サーバーから (https のような暗号化されたチャネルを介して) ファイルをフェッチし、ユーザー。

したがって、ユーザーがソースを表示しても、オリジンサーバーはわかりません...クラウドフロントディストリビューションしかわかりません。

ここでこれを設定する方法の詳細:

http://blog.codeship.io/2012/05/18/Assets-Sprites-CDN.html

于 2013-01-08T20:19:32.253 に答える
-1

[このスレッドが古いことは承知していますが、数か月後にそれを見る私のような人のために回答しています。]

私が読んだり見たりしたことから、CloudFront はリクエストで一貫して自分自身を識別しません。ただし、CloudFront ディストリビューションで robots.txt をオーバーライドすることで、この問題を回避できます。

1) robots.txt という 1 つのファイルのみを含む新しい S3 バケットを作成します。それが CloudFront ドメインの robots.txt になります。

2) AWS コンソールのディストリビューション設定に移動し、[Create Origin] をクリックします。バケットを追加します。

3) [動作] に移動し、[動作の作成] をクリックします: パス パターン: robots.txt オリジン: (新しいバケット)

4) robots.txt の動作の優先度を高く (数値を低く) 設定します。

5) 無効化に移動し、/robots.txt を無効化します。

これで、abc123.cloudfront.net/robots.txt がバケットから提供され、それ以外はすべてドメインから提供されます。いずれかのレベルでのクロールを個別に許可/禁止することを選択できます。

別のドメイン/サブドメインもバケットの代わりに機能しますが、なぜ面倒なことになるのですか.

于 2013-05-16T05:13:51.833 に答える