24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

たった2行で簡易画像Proxyサーバを作る

Last updated at Posted at 2015-03-18

DocumentRootにphpファイルを一個置いて、

proxy.php
<?php
header("Content-type:image/png");
echo (file_get_contents("https://" . substr($_SERVER['PATH_INFO'],1)));

下記のようなURLにアクセスしてみると、あーら不思議、Googlのロゴが表示されます!!

google

  • あくまで簡易実装なので、大規模環境ではNginxやApacheのレイヤでやるのがいいと思います。
  • この例ではHTTP 4xx,5xxのエラーをハンドリングできてないので、ちゃんとやるならやったほうがいいでしょう
  • Content-typeを動的に決定するようにすれば画像以外にも対応できます。
24
23
8

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?