LoginSignup
1
1

More than 3 years have passed since last update.

nginxのリバースプロキシで広告を入れてみた

Last updated at Posted at 2019-09-17

自分のブログから転載。
https://blog.haniokasai.com/2016/11/nginx.html

jenkinsサーバーを運用していたのですが、広告をいれてみたいなぁと思い?手法を検討。

リバースプロキシで広告を埋め込む方法を探しました。
http_sub_moduleで置き換えられるらしいのですが、わざわざmake時にconfigureしてあげるのも嫌だと思います。

調べてみると、nginx-fullには、ngx_http_substitutions_filter_moduleが入っていて、これを使えばいけました。

apt install nginx-full

んで、/etc/nginx/conf.dにリバースプロキシーの設定を書く。

server {
    listen          80;
    server_name     jenkins.haniokasai.com;
    location / {
        proxy_pass      http://localhost:8080;
        proxy_set_header Accept-Encoding "";//gzipがなんとからしい
        subs_filter_types text/html; //対象のデータ形式を決める
        subs_filter '</header>'  '</header><script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script><ins class=\"adsbygoogle\"     style=\"display:block\"     data-ad-client=\"かきかえて\"     data-ad-slot=\"かきかえて\"     data-ad-format=\"auto\"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>';
    }
}

これで、nginxをリスタートをすると表示されるでしょう

参考資料

それっぽい資料

1
1
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
1
1