Saturday, November 30, 2013

How to setup proxy autoconfiguration in Centos 6

Here are the steps to add a proxy configuration script to your squid server so that your browser will discover the proxy automagically.

First create the file /var/www/html/wpad.dat on your server. Add the following contents:

function FindProxyForURL(url, host) { return "PROXY mysquid:3128"; } 

This is the simplest javascript code to make it work. You can find more examples here.

If you haven't got httpd, install it

yum install httpd


Add a file wpad.conf in your /etc/httpd/conf.d directory with the contents:

<Directory /var/www/html>
Order deny,allow
Deny from all
# add IP address you allow
Allow from 172.16.1.1/16
</Directory>

Edit the /etc/httpd/conf/httpd.conf file and add the following lines to correctly set the mime type of the .dat file:

AddType application/x-ns-proxy-autoconfig .pac
AddType application/x-ns-proxy-autoconfig .dat

The browser will search for http://wpad/wpad.dat when discovering proxies.

Now the real trick is to add an address record (not an alias, this does not work with all browsers) in your DNS configuration that points to your apache server serving the wpad.dat file

A wpad.my-local-net.com 172.1.1.1 

Make sure to open the firewall for the apache web server serving your wpad.dat file.


No comments:

Post a Comment