linux 上的 http proxy

Table of Contents

在 Linux 上配置 HTTP 代理可以通过以下几种方式进行:

1. 在环境变量中配置

常用的方法是在环境变量中设置 HTTP 和 HTTPS 代理。可以编辑用户的 shell 配置文件(例如 .bashrc.zshrc),添加以下行:


export http_proxy=http://proxy_server_address:proxy_port
export https_proxy=https://proxy_server_address:proxy_port
export ftp_proxy=ftp://proxy_server_address:proxy_port
export no_proxy="localhost,127.0.0.1,::1"

    •   proxy_server_address: 代理服务器的地址。
    •   proxy_port: 代理服务器的端口。
    •   no_proxy: 不使用代理的地址,通常是本地 IP。

设置完成后,重新加载配置文件:

source ~/.bashrc  # 或 source ~/.zshrc

2. 为特定程序配置

有些程序允许在其配置文件中单独配置代理,例如 curl 和 git。

配置 curl 代理

可以直接通过命令行为 curl 配置代理:

curl -x http://proxy_server_address:proxy_port http://example.com

也可以在 ~/.curlrc 中设置:

proxy = http://proxy_server_address:proxy_port

配置 git 代理

使用如下命令为 git 配置全局代理:

git config --global http.proxy http://proxy_server_address:proxy_port
git config --global https.proxy https://proxy_server_address:proxy_port

要删除代理配置,可以执行:

git config --global --unset http.proxy
git config --global --unset https.proxy

3. 通过 apt 配置(适用于 Debian/Ubuntu)

如果使用 apt 进行软件包管理,可以为其配置代理。在 /etc/apt/apt.conf.d/ 目录下创建一个新的配置文件(如 proxy.conf),并添加如下内容:

Acquire::http::Proxy "http://proxy_server_address:proxy_port/";
Acquire::https::Proxy "https://proxy_server_address:proxy_port/";

4. 通过 GNOME 网络设置配置

对于使用 GNOME 桌面的用户,可以通过图形界面配置代理:

    1.  打开 “设置” > “网络”。
    2.  在网络设置页面底部找到 “网络代理”。
    3.  选择 “手动” 并输入 HTTP、HTTPS、FTP 代理服务器的地址和端口。

通过这些方法,可以方便地为系统或特定应用配置 HTTP 代理。

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: 似水流年