Friday 31 January 2014

How to Use WGET with a Proxy Server

How to Use WGET with a Proxy Server

Question sent in from Brad in South Florida.

Q: My work has a mandatory proxy server.  I think this is what is stopping wget from fetching pages.  Is there a way to allow wget to go through our proxy server?

A: Yes, here is a simple how-to on getting wget to respect proxy settings. Just like everything else in Linux there is more than one way to make this happen.

Option 1:  Set the http_proxy environmental varible.

See this article to learn how to set, export and make the http_proxy variable global for a single user or all users:

How to Set the http_proxy Variable in Linux

Option 2: The preferred method is to configure wget to work with your proxy settings.

This option is best if you only need wget to work with the proxy from the command line, or you need wget to use a different proxy from the one set in the environment with option 1.  If you have multiple command line tools, most can be configured on their own or you can use option one.

You can edit the wget configuration file to tell it what proxy server to use for http, https and ftp connections. This file resides at /etc/wgetrc on most Red Hat, Fedora and CentOS systems.  I believe Ubuntu stores the file in the same location.

Open /etc/wgetrc in a text editor (vi, nano, gedit, etc..) and look for these lines which are commented out:

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
You will need to uncomment (remove the leading pound sign) these lines and add the correct information for your proxy like so:

# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://proxy.yourdomain.com:8080/
http_proxy = http://proxy.yourdomain.com:8080/
ftp_proxy = http://proxy.yourdomain.com:8080/

Save the file and now wget will work on the command line through the proxy you just set.

If your proxy requires authentication, add the following lines to your wgetrc file:
http_proxy=http://proxy.yourdomain.com:8080/
proxy_user=user
proxy_password=password

No comments:

Post a Comment