Squid 備忘録

sudo yum install squid
sudo service squid start

SELinux に怒られたら audit2allow とか

/etc/squid/squid.conf いちおうそのままでも動く

https://centossrv.com/squid.shtml
http://vogel.at.webry.info/201306/article_19.html

Java でアクセス

        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 3128));
        URL url = new URL("http://google.com/");
        HttpURLConnection con = (HttpURLConnection)url.openConnection(proxy);

認証がある場合

class ProxyAuthenticator extends Authenticator {

        private String user, password;

        public ProxyAuthenticator(String user, String password) {
            this.user = user;
            this.password = password;
        }

        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(user, password.toCharArray());
        }
    }

...

Authenticator.setDefault(new ProxyAuthenticator("test", "password"));
        <property name="http.proxyHost" value="localhost"/>
        <property name="http.proxyPort" value="3128"/>
        <property name="http.proxyUser" value="test"/>
        <property name="http.proxyPassword" value="password"/>
        <property name="https.proxyHost" value="localhost"/>
        <property name="https.proxyPort" value="3128"/>
        <property name="https.proxyUser" value="test"/>
        <property name="https.proxyPassword" value="password"/>