Skip to content

Instantly share code, notes, and snippets.

@kubosuke
Last active November 27, 2019 14:07
Show Gist options
  • Save kubosuke/192f1d0e1143d1c7069a282e56d71975 to your computer and use it in GitHub Desktop.
Save kubosuke/192f1d0e1143d1c7069a282e56d71975 to your computer and use it in GitHub Desktop.

下記のように、set_real_ip_fromにLBやIngressのIPを記載し、real_ip_recursiveを設定することで、remote_addr変数にクライアントの ソース元IPを入れることができるようです。

       ##                                                                                                                                                                                          
        # Logging Settings                                                                                                                                                                          
        ##                                                                                                                                                                                          
        real_ip_header X-Forwarded-For;
        set_real_ip_from 130.211.0.0/22;
        set_real_ip_from 35.191.0.0/16;
        set_real_ip_from 107.178.252.189;
        real_ip_header    X-Forwarded-For;
        real_ip_recursive on;

log_format  main  'remote_addr is [$remote_addr] - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

        access_log /var/log/nginx/access.log main;

以前のトライアル

  • resqueポッドにnginxコンテナを追加(イメージ:https://hub.docker.com/_/nginx)
  • resqueコンテナを8080アクセスに、nginxコンテナを80アクセスとし、resqueコンテナへのアクセスポートを80に変更
  • バックエンドへのアクセス

TODO 8/6

  • set_real_ip_fromにIngressなどのIPを記載
  • remote_addrにクライアントのGIPが記載されることを確認
  • location項にて、allow, denyによりIPフィルタリングを実現
@kubosuke
Copy link
Author

kubosuke commented Aug 6, 2019

現在いくつか編集を加えたので、環境が乱れています、、元に戻す場合は上記ファイルにてPUSHお願いします。

残務は次の通りです。

  • ヘルスチェック用のエンドポイントを作成
  • それ以外の全てのLOCATIONについて、バックエンドへプロキシする設定を構築
  • ヘルスチェック先を上述のエンドポイントに変更

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment