🍡

各種システム及びコマンドのプロキシ設定ガイド

2025/01/17に公開

はじめに

既に3週間は何かの病気に掛かり続けている @___nix___ です。

背景

制約のある環境では経路も限定されていることがあります。
或いは特定のIPからの接続のみ許可されているケースもあります。

そんな時はプロキシを経由して外部にアクセスします。

概要

プロキシ経由のアクセスですが、OSの設定をしたとしてもシステムやコマンドが独自に経路を決めてしまうので、「あれ?設定したのにプロキシ経由にならないな」ということが発生します。

今回、OSやシステム、或いはコマンドによるプロキシ設定をまとめてみました。

設定方法

1. Linux システム全般

環境変数による設定

export HTTP_PROXY=http://xxx.xxx.xxx.xxx:80
export HTTPS_PROXY=http://xxx.xxx.xxx.xxx:80
export http_proxy=http://xxx.xxx.xxx.xxx:80
export https_proxy=http://xxx.xxx.xxx.xxx:80
export no_proxy=localhost,127.0.0.1

システム全体の設定 (/etc/environment)

HTTP_PROXY=http://xxx.xxx.xxx.xxx:80
HTTPS_PROXY=http://xxx.xxx.xxx.xxx:80
http_proxy=http://xxx.xxx.xxx.xxx:80
https_proxy=http://xxx.xxx.xxx.xxx:80
no_proxy=localhost,127.0.0.1

2. パッケージマネージャー

yum (/etc/yum.conf)

proxy=http://xxx.xxx.xxx.xxx:80

apt (/etc/apt/apt.conf)

Acquire::http::Proxy "<http://xxx.xxx.xxx.xxx:80>";
Acquire::https::Proxy "<http://xxx.xxx.xxx.xxx:80>";

3. 開発ツール

Docker

Dockerfile内

ENV http_proxy <http://xxx.xxx.xxx.xxx:80>
ENV https_proxy <http://xxx.xxx.xxx.xxx:80>

Docker デーモン設定 (/etc/systemd/system/docker.service.d/http-proxy.conf)

[Service]
Environment="HTTP_PROXY=http://xxx.xxx.xxx.xxx:80"
Environment="HTTPS_PROXY=http://xxx.xxx.xxx.xxx:80"

Git

git config --global http.proxy <http://xxx.xxx.xxx.xxx:80>
git config --global https.proxy <http://xxx.xxx.xxx.xxx:80>

npm

npm config set proxy <http://xxx.xxx.xxx.xxx:80>
npm config set https-proxy <http://xxx.xxx.xxx.xxx:80>

composer

composer config -g github-oauth.github.com <token>
composer config -g http-basic.repo.packagist.com token <token>

4. ユーティリティツール

wget (/etc/wgetrc または ~/.wgetrc)

http_proxy = <http://xxx.xxx.xxx.xxx:80>
https_proxy = <http://xxx.xxx.xxx.xxx:80>

curl (~/.curlrc)

proxy-user = "username:password"
proxy = "<http://proxy.xxx.co.jp:80>"

pecl/pear

pear config-set http_proxy <http://xxx.xxx.xxx.xxx:80>

5. プログラミング言語特有の設定

Python (pip)

pip install --proxy <http://xxx.xxx.xxx.xxx:80> package_name
# または ~/.pip/pip.conf
[global]
proxy = <http://xxx.xxx.xxx.xxx:80>

Maven (settings.xml)

<proxies>
  <proxy>
    <id>example-proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>proxy.example.com</host>
    <port>80</port>
  </proxy>
</proxies>

終わりに

以上ですが、少しは皆様の役に立てたでしょうか。
逆に設定箇所がまとまっていないのでこれらの設定に中々気が付けないということもあるかもしれませんね。

一言

恐らくですが、コロナとインフルとマイコプラズマと副鼻腔炎を併発してます。
皆様もお気を付けて。

Discussion