背景:
有些linux服务器处于内网,并且没有公网ip,故要想与外网进行http/https通信只能通过nat或者加proxy的方式。nat服务器有网段的限制,而http/https proxy代理则没有,使用起来也方便。
linux系统设置http/https proxy的方法,在/etc/bashrc或者/etc/profile中添加如下环境变量:
方法一:写入配置文件永久生效
vim /etc/profile
export http_proxy=x.x.x.x:8080
export https_proxy=$http_proxy
export ftp_proxy=user:password@x.x.x.x:8080
export no_proxy=harbor.zc.com,localhost,127.0.0.1,10.7.22.2,10.7.21.2
http_proxy:http协议使用代理服务器地址;
https_proxy:https协议使用安全代理地址;
ftp_proxy:ftp协议使用代理服务器地址;
no_proxy:不使用代理的主机或IP。
生效:source /etc/profile
方法二:命令行执行 临时生效
设置代理:
export http_proxy=x.x.x.x:8080
export https_proxy=$http_proxy
取消代理:
unset http_proxy
unset https_proxy