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

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

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

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

AWS(Amazon Web Services)

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

Q&A

2回答

5924閲覧

squidを用いたプロキシサーバーの構築について

tomohiro_h0608

総合スコア12

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

AWS(Amazon Web Services)

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

0グッド

0クリップ

投稿2019/07/15 02:46

編集2022/01/12 10:55

EC2インスタンスを使ってプロキシサーバを構築しているのですが、Privateserverから特定のサイト(yahoo.co.jp)へアクセスのみ、プロキシ経由でサイトへアクセスする方法について

APIをPrivateサーバで実行する場合、特定のサイトへのアクセスのみProxyサーバ経由で行いたいと考えています。
APIのアクセス先に応じてProxyを経由するように設定するには、どうしたらよろしいでしょうか。

イメージ説明
確認事項
ping での疎通確認

ping 10.1.0.14 PING 10.1.0.14 (10.1.0.14) 56(84) bytes of data. 64 bytes from 10.1.0.14: icmp_seq=1 ttl=255 time=0.868 ms 64 bytes from 10.1.0.14: icmp_seq=2 ttl=255 time=1.01 ms ^C --- 10.1.0.14 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1014ms rtt min/avg/max/mdev = 0.868/0.941/1.014/0.073 ms

telnetでのプロキシサーバとの疎通確認

telnet 10.1.0.14 3128 Trying 10.1.0.14... Connected to 10.1.0.14. Escape character is '^]'. GET http://183.79.135.206/ HTTP/1.1 200 OK Date: Mon, 15 Jul 2019 02:40:50 GMT P3P: policyref="http://privacy.yahoo.co.jp/w3c/p3p_jp.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV" X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN ~省略

curlコマンドでリクエスト時にProxyの利用を指定することができる

curl http://169.254.169.254/latest/meta-data/instance-id i-09ed9b8430a429a8a curl --proxy 10.1.0.14:3128 http://169.254.169.254/latest/meta-data/instance-id i-03d35a3ea0bfcf191

発生している問題・エラーメッセージ

サイトへのアクセスのタイムアウト

curl http://183.79.135.206/ curl: (7) Failed to connect to 183.79.135.206 port 80: Connection timed out

squid.conf

# # Recommended minimum configuration: # # Example rule allowing access from your local networks. # Adapt to list your (internal) IP networks from where browsing # should be allowed acl localnet src 10.1.0.0/16 # 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 localnet src 127.0.0.1/32 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 acl allow_hosts src 54.162.26.86/32 http_access allow allow_hosts # # 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 forwarded_for off # And finally deny all other access to this proxy http_access allow all #http_access deny all # Squid normally listens to port 3128 http_port 3128 # 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 forwarded_for off visible_hostname unknown request_header_access X-Forwarded-For deny all request_header_access Via deny all request_header_access Cache-Control deny all max_filedesc 4096 http_access deny all

正直squid.confの設定をどのように行えばいいか理解できていません。
どうかお力添えをお願いします。

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

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

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

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

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

hentaiman

2019/07/15 03:00

squid建ってるだけでproxy設定してないからじゃなくて?
tomohiro_h0608

2019/07/15 03:29

サイトへアクセスするPrivateserverのルートデータでsquidを建てたProxyServerへルーティングしているので、できると思ったのですが、
hentaiman

2019/07/15 03:38

そこについてはわからんけど、ためしにproxy設定してからcurl打って成功するようならルーティングの設定に失敗しててsquidは何もしてないってことがわかるので次の対策たてられるんじゃないでしょうか
raccy

2019/07/15 04:19

結局解決できたのですか?そうであれば、解決内容を自己回答して、BAをつけておいてください。
tomohiro_h0608

2019/07/15 04:23

APIでのリクエストでProxyを利用することを考えていたのでcurl時にproxy利用を設定するのではなく、アクセス先によってProxyに振り分けたいと考えています。
mit0223

2019/07/17 08:14

・APIを呼ぶプログラムはなんですか?HTTPクライアントのライブラリは何を使用してますか? ・プロキシを経由させたい理由によってはリバースプロキシのほうが良いかもしれないのですが、プロキシを経由させたい理由はなんですか?
guest

回答2

0

Squid を Transparent Proxy として設定し、iptables で 80番ポートを 3128番ポートに REDIRECT する必要があります。

(参考) https://teratail.com/questions/113982

もし、HTTPクライアントで、ブラウザの .pac ファイルのような方法で振り分けできるのであれば、そちらの方が簡単だと思います。

投稿2019/07/15 06:44

TaichiYanagiya

総合スコア12141

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

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

0

  1. 単純にPrpxy.pacを書いて、目的とする「Yahoo」以外は「Return Direct」を返すことで制御可能です。
  2. 「Proxy.pac」は、当該ProxyにApache等を立てて提供し、アクセスする端末側でProxy.pacの設定を行う事で実現できます。
  3. 端末側でDHCPサーバを利用している場合、DHCPからProxy.pac設定を配布可能です。

  →DHCP設定周りは長くなるので、必要なら別のQAを立てて下さい。

【参考URL】
WebブラウザのProxy設定を行うための4つの方法(WPADのススメ)→@IT
プロキシPacファイルとそのサンプルについて(Cisco)

投稿2019/08/18 05:11

BUN-G

総合スコア55

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問