質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
冗長化

冗長化とは、システムの一部に障害が発生してもサービスを継続できるようシステム構築を行うこと。要する量より多く予備装置を準備しバックアップとして配置しておきます。また、冗長化による安全性は、冗長性と呼ばれています。

Squid

Squidは、TCP/IPネットワークでのユーザーとサーバの通信を中継するオープンソースのプロキシサーバソフト。リバースプロキシやキャッシュサーバとして使用することも可能です。

proxy

proxy(プロキシー)は、企業などの内部コンピュータとインターネットの中間に位置し、例えば直接インターネットに接続できない内部コンピュータの代理としてインターネットに接続する等をするシステム、もしくは代理として機能を実行するソフトウェアです。内部ネットワークへのアクセスを一元管理し、内部からの特定の種類の接続以外を遮断すること、外部からの不正アクセスを拒否することなどに用いられます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

5103閲覧

[AWS]フォワードプロキシをELBで冗長化したい

terumin

総合スコア17

冗長化

冗長化とは、システムの一部に障害が発生してもサービスを継続できるようシステム構築を行うこと。要する量より多く予備装置を準備しバックアップとして配置しておきます。また、冗長化による安全性は、冗長性と呼ばれています。

Squid

Squidは、TCP/IPネットワークでのユーザーとサーバの通信を中継するオープンソースのプロキシサーバソフト。リバースプロキシやキャッシュサーバとして使用することも可能です。

proxy

proxy(プロキシー)は、企業などの内部コンピュータとインターネットの中間に位置し、例えば直接インターネットに接続できない内部コンピュータの代理としてインターネットに接続する等をするシステム、もしくは代理として機能を実行するソフトウェアです。内部ネットワークへのアクセスを一元管理し、内部からの特定の種類の接続以外を遮断すること、外部からの不正アクセスを拒否することなどに用いられます。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2020/12/16 05:48

スクレイピング用にAWSでプロキシサーバーを構築しています。
EC2でプロキシサーバー(Squid)を2台構成にして、NLBで冗長化します。
イメージ説明

上記の環境を作ってアクセスしてみたところ、以下のようにエラーになりました。

# 4578ポートでアクセスした場合のエラー http_proxy=http://xxxx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com:4578 curl http://www.ugtop.com/spill.shtml -v * Uses proxy env variable http_proxy == 'http://xxxx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com:4578' * Trying xx.xxx.xx.xxx... * TCP_NODELAY set * Connected to xxxx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com (xx.xxx.xx.xxx) port 4578 (#0) > GET http://www.ugtop.com/spill.shtml HTTP/1.1 > Host: www.ugtop.com > User-Agent: curl/7.64.1 > Accept: */* > Proxy-Connection: Keep-Alive > * Empty reply from server * Connection #0 to host xxxx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com left intact curl: (52) Empty reply from server * Closing connection 0 # 80ポートでアクセスした場合のエラー * Uses proxy env variable http_proxy == 'http://xxx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com:80' * Trying xx.xxx.xx.xxx... * TCP_NODELAY set * Connection failed * connect to xx.xxx.xx.xxx port 80 failed: Operation timed out * Trying xx.xxx.xx.xxx... * TCP_NODELAY set * Connection failed * connect to 54.168.145.147 port 80 failed: Operation timed out * Failed to connect to xx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com port 80: Operation timed out * Closing connection 0 curl: (7) Failed to connect to xx-proxy-nlb2-xxxx.elb.ap-northeast-1.amazonaws.com port 80: Operation timed out

NLB無しでEC2単体の場合は、うまく動いていたので、おそらくNLBかSquidの設定周りが原因だと思っております。
現状の設定は以下の通りです。
どこが間違っているのか、ご教示頂けましたら幸いです

現状の設定

NLB

スキーム: インターネット向け IPアドレスタイプ; ipv4 # リスナー プロトコル:TCP ポート: 4578 #Squidのポート #アベイラビリティーゾーン VPC: 上記構成図のVPC サブネット: 上記構成図のサブネットを2つ指定 IPアドレス: 2つともEIPを割り当て # ターゲットグループ ターゲットタイプ:インスタンス プロトコル:TCP ポート: 4578 VPC: 上記構成図のVPC ターゲット; 上記構成図のEC2を2つとも指定。ポートは4578、ステータスはhealthy Proxy protocol v2: Enabled

EC2

セキュリティグループは以下。
イメージ説明
イメージ説明

Squid

acl localnet src 10.0.0.0/8 # RFC1918 possible internal network acl localnet src 10.0.2.0/8 # RFC1918 possible internal network acl localnet src 172.16.0.0/12 # RFC1918 possible internal network acl localnet src 192.168.0.0/16 # RFC1918 possible internal network acl localnet src fc00::/7 # RFC 4193 local private network range acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT #-- proxy設定---------------- #ポートの指定とproxy接続時にproxy protocolを必須にする http_port 4578 require-proxy-header http_port 4578 #NLBのIPをACLに追加 ## NLBのEIP acl nlb_ip src xx.xx.xx.xx acl nlb_ip src xx.xx.xx.xx ## NLBのローカルIP acl nlb_ip src 10.0.0.19 acl nlb_ip src 10.0.2.179 #クライアントIPをACLに追加 ## スクレイピングシステムのグローバルIP acl client_ip src xx.xx.xx.xx #URLフィルタリング #acl whitelist dstdomain "/etc/squid/whitelist" #Proxy Protocolの利用許可 proxy_protocol_access allow localnet proxy_protocol_access allow nlb_ip proxy_protocol_access allow client_ip proxy_protocol_access deny all #httpアクセスの許可 http_access permit nlb_ip #クライアントの許可とホワイトリストの適用 http_access permit client_ip #----------------------------- # # Recommended minimum Access Permission configuration: # # Deny requests to certain unsafe ports http_access deny !Safe_ports # Deny CONNECT to other than secure SSL ports http_access deny CONNECT !SSL_ports # Only allow cachemgr access from localhost http_access allow localhost manager http_access deny manager # We strongly recommend the following be uncommented to protect innocent # web applications running on the proxy server who think the only # one who can access services on "localhost" is a local user #http_access deny to_localhost # # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS # # Example rule allowing access from your local networks. # Adapt localnet in the ACL section to list your (internal) IP networks # from where browsing should be allowed http_access allow localnet http_access allow localhost # Uncomment and adjust the following to add a disk cache directory. #cache_dir ufs /var/spool/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /var/spool/squid # # Add any of your own refresh_pattern entries above these. # refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|?) 0 0% 0 refresh_pattern . 0 20% 4320 http_access allow all client_persistent_connections off server_persistent_connections off # 以下、マニュアル設定------------------------------------- # ランダムIP数(スクレイピング用にIPを分散する) acl balance random 1/4 balance_on_multiple_ip on # 拒否設定まわり visible_hostname unknown forwarded_for off request_header_access X-Forwarded-For deny all request_header_access Via deny all request_header_access Cache-Control deny all reply_header_access X-Forwarded-For deny all reply_header_access Via deny all reply_header_access Cache-Control deny all max_filedesc 65535 # スクレイピング用の分散ElasticIPに紐付けたprivate IP tcp_outgoing_address 10.0.2.162 balance tcp_outgoing_address 10.0.2.163 balance tcp_outgoing_address 10.0.2.164 balance tcp_outgoing_address 10.0.2.165 balance # キャッシュしない設定 acl NOCACHE src all cache deny NOCACHE

以上、よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

curl: (52) Empty reply from server

Proxy Protocol まわりに原因があるように思います。
/var/log/squid/cache.log に以下のようなログが出ていないでしょうか?

PROXY client not permitted by ACLs from local=xxx.xxx.xxx.xxx:4578 remote=(NLBのIPアドレス):(ポート)

接続元:NLBのIPアドレスacl nlb_ip 以外になっていて、proxy_protocol_access で許可されていないのでは? という推測です。

切り分けのため、NLB, Squid とも Proxy Protocol 設定を無効にするとどうなるでしょうか?

投稿2020/12/17 01:37

TaichiYanagiya

総合スコア12141

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

terumin

2020/12/17 08:31

ありがとうございます! ログに出ていたエラーをググったところ、Squidのバージョンが古かったらしく、 アップデートで一旦エラーは出なくなりました。 ですが、今度はまた別の問題が起きたため、 新規で質問を立て直しました(^^;) https://teratail.com/questions/310829?modal=q-comp 一旦こちらはクローズしようと思います。 ご回答ありがとうございました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問