Movatterモバイル変換


[0]ホーム

URL:


BLOGTIMES

cles::blog

平常心是道
« :: »
2015/10/20

CentOS 7.x でも mod_extract_forwarded を使ってリバースプロキシ経由のアクセス元IPを書き換えたい

  httpd24  centos7 
このエントリーをはてなブックマークに追加

しばらく前にリバースプロキシ経由のアクセス元IPを書き換える というエントリでmod_extract_forwarded をインストールする方法を紹介しましたが、これと同じことを CentOS 7 でやろうとしたらハマってしまって思いのほか時間を取られてしまったので後学のためのメモを残しておきます。

CentOS 6.x のときは epel を使えば yum でインストールするだけの楽ちん作業だったので、同じようにいくだろうと読んでいましたが初っ端から大誤算。まずCentOS 7 では epel に mod_extract_forwarded は含まれていません。他のリポジトリも探しましたが同様です。この理由は CentOS 6 -> CentOS 7 に伴って Apache のバージョンが 2.2 -> 2.4 に変更されているのですが、mod_extract_forwarded がそもそも 2.4 に対応していないので、含めようにも含められないというのが真相のようです。

このあたりの事情や、2.4 から導入されたmod_remoteip については下記のエントリが詳しいです。

今回はこの方の書かれたmatsumoto-r/mod_extract_forwarded_for_2.4 をインストールすることにします。

以下、インストールメモ。

モジュールのコンパイルとインストール

ソースが GitHub にあるので、これを clone して apxs を使ってビルドとインストールを行います。

yum install httpd-devel -ygit clone https://github.com/matsumoto-r/mod_extract_forwarded_for_2.4.gitcd mod_extract_forwarded_for_2.4apxs -c -i mod_extract_forwarded.c

設定ファイルの作成と設定の反映

以下のような感じで設定ファイルを生成してやります。
MEFaccept の部分はリバースプロキシの IP アドレスに読み替えてください。

cat << 'EOS' > /etc/httpd/conf.modules.d/01-extract_forwarded.confLoadModule extract_forwarded_module modules/mod_extract_forwarded.so# MEForder can have either of two value 'refuse,accept' or 'accept,refuse' and# specifies the order in which the information in two associated directives,# MEFaccept and MEFrefuse, are intepreted. The MEFaccept and MEFrefuse# directives are each used to spcifiy one or more IP numbers.MEForder refuse,accept# MEFrefuse can be 'all' OR a list of IP numbers and/or domain names of trusted# proxy servers whose IP number can be derived by DNS from the domain name.# The presence of 'all' overrides any particular IP numbers and means that no# proxy servers are to be trusted. Individual IP numbers mean that those proxy# servers having them are not to be trusted. This defaults to 'all'.MEFrefuse all# MEFaccept can be 'all' OR a list of IP numbers and/or domain names of trusted# proxy servers whose IP number can be derived by DNS from the domain name.# The presence of 'all' overrides any particular IP numbers and means that all# proxy servers are to be trusted.# Individual IP numbers mean that those the proxy servers having them are to be# trusted. This defaults to an empty list of trusted IP numbers.MEFaccept 192.168.###.### # Normal mode of use is to say:## MEForder refuse,accept# MEFrefuse all# MEFaccept <space separated list of your trusted proxy servers' IP numbers>## with the MEForder directive saying apply the MEFrefuse rule first then the# MEFaccept rule.# The MEFrefuse rule says do not trust any proxy servers but this is selectively# overridden for particular IP numbers listed by the MEFaccept directive.# MEFaddenv can be 'off', 'on' (the default) or a string. 'off' means that when# spoofing, do not add an environment variable whose value is the IP number of# the connecting machine. 'on' means that when spoofing, add an environment# variable called 'MEF_RPROXY_ADDR' whose value is the IP number of the# connecting machine.# A string means that when spoofing, add an environment variable named by the# string supplied whose value is the IP number of the connecting machine.MEFaddenv on# MEFdebug can be 'on' or 'off' (the default). When turned 'on' information# about how the mod_extract_forwarded module is processing every request to your# Apache 2 server, and any associated internal redirects or subsrequests, is# written to the server's error_log.# The amount of output written and the way it is generated is such that you# would never normally want to turn this feature on.# This feature is intended for debugging operation of the mod_extract_forwarded# module and it is unlikely you will want to do that.MEFdebug offEOS

最後に apache を restart してやれば完了です。

systemctl restart httpdsystemctl status httpd

    byhsur at 20:06[5年前][4年前][3年前][2年前][1年前][1年後][2年後][3年後][4年後][5年後] |
    こんな記事もあります 「書き換え IP CentOS
    2024 年の人気エントリ Top 100
    世界サーバ投げ選手権 (WSTC) が開催されるらしい
    Celestica Seastone DX010 という 100GbE スイッチを手にいれた
    Google が AI によるファイル判別ツールをリリース
    個人情報保護委員会が進撃の巨人とコラボ
    Windows Update の日 ( 2024 年 2 月 )
    中国企業が対日工作として偽サイトを作成している
    Windows にも sudo が導入される
    bluesky が招待制を終了
    GPIF の直近四半期の運用成績は +5.7 兆円
    トラックバックについて
    Trackback URL:
    お気軽にどうぞ。トラックバック前にポリシーをお読みください。[policy]
    このエントリへのTrackbackにはこのURLが必要です→https://blog.cles.jp/item/7980
    Trackbacks
    このエントリにトラックバックはありません
    Comments
    愛のあるツッコミをお気軽にどうぞ。[policy]
    古いエントリについてはコメント制御しているため、即時に反映されないことがあります。
    コメントはありません
    Comments Form

    コメントは承認後の表示となります。
    OpenIDでログインすると、即時に公開されます。

    OpenID を使ってログインすることができます。

    Identity URL:Yahoo! JAPAN IDでログイン

    « :: »
    Copyright © 2004-2023 by CLES All Rights Reserved.
    サイト内検索
    検索ワードランキング
    へぇが多いエントリ
    閲覧数が多いエントリ
    1 .アーロンチェアのポスチャーフィットを修理(99779)
    2 .福岡銀がデマの投稿者への刑事告訴を検討中(99168)
    3 .年次の人間ドックへ(99159)
    4 .三菱鉛筆がラミーを買収(98763)
    5 .2023 年分の確定申告完了!(1つめ)(98729)
    最新のエントリ
    cles::blogについて
    誰が書いてる?
    最近行った場所
    サイトポリシー
    タグ一覧
    検索ワードランキング

    Referrers

      Powered by CLES
      Nucleus CMS v3.31SP3/w memcached
      21377094(W:7719 Y:1720 T:1193)
      cles::blogのはてなブックマーク数
      benchmark


      [8]ページ先頭

      ©2009-2025 Movatter.jp