LoginSignup
9
8

More than 5 years have passed since last update.

リバースプロキシを利用して外部サイトのhttp画像をhttpsで表示してみた

Last updated at Posted at 2013-06-09

AmazonのMWSを利用したサイトを構築していて、下記の問題に遭遇した。
sslを利用したページで商品の画像を表示したいが、amazonの画像はhttpsではアクセスできない。下記のメッセージが出る。

Service Unavailable

The server is temporarily unable to service your request. Please try again later.
Reference #6.f5bcf648.1370745556.563d5fc

httpの画像URLのままだと、SSLのセキュリティ警告がでてしまうので、、かっこわるい。。

そこでNginxのリバースプロキシを利用する。

/etc/nginx/nginx.conf
location /images {
                        proxy_pass http://ec2.images-amazon.com:80;
                }

画像パスを

url =  url.gsub(/http\:\/\/ec2\.images\-amazon\.com/,'https://hogehoge.com')

これで、下記のように自分のドメインからでも、amazonの画像がsslで表示された!

スクリーンショット 2013-06-09 11.18.56 AMのコピー.png

ネットで、それらしい情報が無かったので、書いてみました。
Amazonのアフィリエイトの方のAPIを使ってこれをやるのは規約違反かもしれないので、注意してください。 問題があるやり方かもしれないので、自己責任で

9
8
0

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
9
8