LoginSignup
24
23

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