<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ginjachris</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ginjachris"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Ginjachris"/>
	<updated>2026-05-01T02:39:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=17570</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=17570"/>
		<updated>2020-05-14T14:23:50Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Blocking domains */  - fixed domain ACL link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will be used to sign it. This spoofed certificate is then presented to the client when they access a site via the proxy.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump bump all&lt;br /&gt;
## Prior to squid 3.5 it was done like this:&lt;br /&gt;
#ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump bump all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dropbox.com/s/6a38vcmksoevfsa/porndomains.acl?dl=1 here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13728</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13728"/>
		<updated>2017-08-15T08:04:05Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* SSL interception or SSL bumping */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will be used to sign it. This spoofed certificate is then presented to the client when they access a site via the proxy.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump bump all&lt;br /&gt;
## Prior to squid 3.5 it was done like this:&lt;br /&gt;
#ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump bump all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=13192</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=13192"/>
		<updated>2017-03-29T11:33:56Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* man darkhttpd */ updated&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.  &lt;br /&gt;
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;/var/files --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under the server root, by default {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
darkhttpd/1.12, copyright (c) 2003-2016 Emil Mikulic.&lt;br /&gt;
usage:	darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:	--port number (default: 8080, or 80 if running as root)&lt;br /&gt;
		Specifies which port to listen on for connections.&lt;br /&gt;
		Pass 0 to let the system choose any free port for you.&lt;br /&gt;
&lt;br /&gt;
	--addr ip (default: all)&lt;br /&gt;
		If multiple interfaces are present, specifies&lt;br /&gt;
		which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
	--maxconn number (default: system maximum)&lt;br /&gt;
		Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
	--log filename (default: stdout)&lt;br /&gt;
		Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
	--chroot (default: don&#039;t chroot)&lt;br /&gt;
		Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
	--daemon (default: don&#039;t daemonize)&lt;br /&gt;
		Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
	--index filename (default: index.html)&lt;br /&gt;
		Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
	--no-listing&lt;br /&gt;
		Do not serve listing if directory is requested.&lt;br /&gt;
&lt;br /&gt;
	--mimetypes filename (optional)&lt;br /&gt;
		Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
	--default-mimetype string (optional, default: application/octet-stream)&lt;br /&gt;
		Files with unknown extensions are served as this mimetype.&lt;br /&gt;
&lt;br /&gt;
	--uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
		Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
	--pidfile filename (default: no pidfile)&lt;br /&gt;
		Write PID to the specified file.  Note that if you are&lt;br /&gt;
		using --chroot, then the pidfile must be relative to,&lt;br /&gt;
		and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
	--no-keepalive&lt;br /&gt;
		Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
	--forward host url (default: don&#039;t forward)&lt;br /&gt;
		Web forward (301 redirect).&lt;br /&gt;
		Requests to the host are redirected to the corresponding url.&lt;br /&gt;
		The option may be specified multiple times, in which case&lt;br /&gt;
		the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
	--forward-all url (default: don&#039;t forward)&lt;br /&gt;
		Web forward (301 redirect).&lt;br /&gt;
		All requests are redirected to the corresponding url.&lt;br /&gt;
&lt;br /&gt;
	--no-server-id&lt;br /&gt;
		Don&#039;t identify the server type in headers&lt;br /&gt;
		or directory listings.&lt;br /&gt;
&lt;br /&gt;
	--ipv6&lt;br /&gt;
		Listen on IPv6 address.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13191</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13191"/>
		<updated>2017-03-29T11:23:13Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Disable SSL interception for certain sites */  amended for squid 3.5 &amp;quot;## e.g ssl_bump bump all&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will sign it.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump bump all&lt;br /&gt;
## Prior to squid 3.5 it was done like this:&lt;br /&gt;
#ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump bump all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13190</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13190"/>
		<updated>2017-03-29T11:21:32Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Amend /etc/squid/squid.conf */ corrected for squid 3.5 &amp;quot;ssl_bump bump all&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will sign it.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump bump all&lt;br /&gt;
## Prior to squid 3.5 it was done like this:&lt;br /&gt;
#ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13189</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13189"/>
		<updated>2017-03-29T10:14:18Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Generate a self-signed certificate with OpenSSL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will sign it.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13188</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13188"/>
		<updated>2017-03-29T10:11:38Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: libressl added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will sign it.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package or {{Pkg|libressl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates libressl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
Whether you are using OpenSSL or LibreSSL, the command to use is still &#039;openssl&#039;.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=13186</id>
		<title>Alpine Package Keeper</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=13186"/>
		<updated>2017-03-28T10:54:36Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: added &amp;quot;Add a local Package&amp;quot; section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--For searching: apk, APK--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because Alpine Linux is designed to run from RAM, package management involves two phases:&lt;br /&gt;
* Installing / Upgrading / Deleting packages on a running system.&lt;br /&gt;
* Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. &#039;&#039;&#039;(RAM-Based Installs Only)&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;apk&#039;&#039;&#039; is the tool used to install, upgrade, or delete software on a running sytem.&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;lbu&#039;&#039;&#039; is the tool used to capture the data necessary to restore a system to a previously configured state.&lt;br /&gt;
&lt;br /&gt;
This page documents the [http://git.alpinelinux.org/cgit/apk-tools.git apk tool] - See the [[Alpine_local_backup|Alpine Local Backup page]] for the lbu tool.&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; tool has the following applets:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[#Add a Package|add]] &lt;br /&gt;
| Add new packages to the running system&lt;br /&gt;
|-&lt;br /&gt;
| [[#Remove a Package|del]]&lt;br /&gt;
| Delete packages from the running system&lt;br /&gt;
|-&lt;br /&gt;
| fix &lt;br /&gt;
| Attempt to repair or upgrade an installed package &lt;br /&gt;
|-&lt;br /&gt;
| [[#Update the Package list|update]] &lt;br /&gt;
| Update the index of available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Info on Packages|info]]&lt;br /&gt;
| Prints information about installed or available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Search for Packages|search]] &lt;br /&gt;
| Search for packages or descriptions with wildcard patterns&lt;br /&gt;
|-&lt;br /&gt;
| [[#Upgrade a Running System|upgrade]]&lt;br /&gt;
| Upgrade the currently installed packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Cache Maintenance|cache]]&lt;br /&gt;
| Maintenance operations for locally cached package repository&lt;br /&gt;
|-&lt;br /&gt;
| version &lt;br /&gt;
| Compare version differences between installed and available packages&lt;br /&gt;
|-&lt;br /&gt;
| index &lt;br /&gt;
| create a repository index from a list of packages&lt;br /&gt;
|-&lt;br /&gt;
| fetch &lt;br /&gt;
| download (but not install) packages&lt;br /&gt;
|-&lt;br /&gt;
| audit &lt;br /&gt;
| List changes to the file system from pristine package install state&lt;br /&gt;
|-&lt;br /&gt;
| verify &lt;br /&gt;
| Verify a package signature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Packages and Repositories =&lt;br /&gt;
&lt;br /&gt;
Software packages for Alpine Linux are digitally signed tar.gz archives containing programs, configuration files, and dependency metadata. They have the extension &amp;lt;code&amp;gt;.apk&amp;lt;/code&amp;gt;, and are often called &amp;quot;a-packs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The packages are stored in one or more &#039;&#039;repositories&#039;&#039;. A repository is simply a directory with a collection of *.apk files.  The directory must include a special index file, named {{Path|APKINDEX.tar.gz}} to be considered a repository.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; utility can install packages from multiple repositories.  The list of repositories to check is stored in {{Path|/etc/apk/repositories}}, one repository per line. If you booted from a USB stick ({{Path|/media/sda1}}) or CD-ROM ({{Path|/media/cdrom}}), your repository file probably looks something like this:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|/media/sda1/apks/}}&lt;br /&gt;
&lt;br /&gt;
In addition to local repositories, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility uses &#039;&#039;&#039;busybox wget&#039;&#039;&#039; to fetch packages using &#039;&#039;http:&#039;&#039;, &#039;&#039;https:&#039;&#039; or &#039;&#039;ftp:&#039;&#039; protocols. The following is a valid repository file:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
/media/sda1/apks&lt;br /&gt;
http://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
https://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
ftp://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Currently, there are no public https or ftp repositories. The protocols are available for local repositories.}}&lt;br /&gt;
&lt;br /&gt;
== Repository pinning ==&lt;br /&gt;
&lt;br /&gt;
You can specify additional &amp;quot;tagged&amp;quot; repositories in {{Path|/etc/apk/repositories}}:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
http://nl.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
@edge http://nl.alpinelinux.org/alpine/edge/main&lt;br /&gt;
@testing http://nl.alpinelinux.org/alpine/edge/testing&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After which you can &amp;quot;pin&amp;quot; dependencies to these tags using:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add stableapp newapp@edge bleedingapp@testing}}&lt;br /&gt;
&lt;br /&gt;
Apk will now by default only use the untagged repositories, but adding a tag to specific package:&lt;br /&gt;
&lt;br /&gt;
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another repository&lt;br /&gt;
&lt;br /&gt;
2. &#039;&#039;allows&#039;&#039; pulling in dependencies for the tagged package from the tagged repository (though it &#039;&#039;prefers&#039;&#039; to use untagged repositories to satisfy dependencies if possible)&lt;br /&gt;
&lt;br /&gt;
= Update the Package list =&lt;br /&gt;
&lt;br /&gt;
Remote repositories change as packages are added and upgraded.   To get the latest list of available packages, use the &#039;&#039;update&#039;&#039; command.  The command downloads the {{Path|APKINDEX.tar.gz}} from each repository and stores it in the local cache, typically {{Path|/var/cache/apk/}}, {{Path|/var/lib/apk/}} or {{Path|/etc/apk/cache/}}.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk update}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
fetch http://dl-3.alpinelinux.org/alpine/v2.1/main/APKINDEX.tar.gz&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|If using remote repositories, it is a good idea to do an &#039;&#039;&#039;update&#039;&#039;&#039; just before doing an &#039;&#039;&#039;add&#039;&#039;&#039; or &#039;&#039;&#039;upgrade&#039;&#039;&#039; command.  That way you know you are using the latest software available.}}&lt;br /&gt;
&lt;br /&gt;
= Add a Package =&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;add&#039;&#039;&#039; to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the &#039;&#039;&#039;add&#039;&#039;&#039; command installs the newest package.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssh&lt;br /&gt;
apk add openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories. To install a package from the edge/testing repository without changing your repository configuration file, use the command below. This will tell apk to use that particular repository.&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add cherokee --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Be careful when using third-party or the testing repository. Your system can go down.}}&lt;br /&gt;
&lt;br /&gt;
= Add a local Package =&lt;br /&gt;
&lt;br /&gt;
To install a locally available apk package, for example if this device has no internet access but you can upload apk packages directly to it, use the &#039;&#039;&#039;--allow-untrusted&#039;&#039;&#039; flag:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /path/to/file.apk}}&lt;br /&gt;
&lt;br /&gt;
Note that multiple packages can be given.  When installing a local package, all dependencies should also be specified.  For example:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk}}&lt;br /&gt;
&lt;br /&gt;
= Remove a Package  =&lt;br /&gt;
Use &#039;&#039;&#039;del&#039;&#039;&#039; to remove a package (and dependencies that are no longer needed.)  &lt;br /&gt;
&lt;br /&gt;
{{cmd|apk del openssh&lt;br /&gt;
apk del openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
= Upgrade a Running System =&lt;br /&gt;
&lt;br /&gt;
To upgrade &#039;&#039;all&#039;&#039; the packages of a running system, use &#039;&#039;&#039;upgrade&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To upgrade &#039;&#039;only a few&#039;&#039; packages, use the &#039;&#039;&#039;add&#039;&#039;&#039; command with the &#039;&#039;-u&#039;&#039; or &#039;&#039;--upgrade&#039;&#039; option:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk add --upgrade busybox &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Remember that when you reboot your machine, the remote repository will not be available until after networking is started. This means packages newer than your local boot media will likely not be installed after a reboot. To make an &amp;quot;upgrade&amp;quot; persist over a reboot, use a [[#Local Cache|local cache]].}}&lt;br /&gt;
&lt;br /&gt;
= Search for Packages =&lt;br /&gt;
The &#039;&#039;&#039;search&#039;&#039;&#039; command searches the repository Index files for installable packages. &lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
* To list all packages available, along with their descriptions: {{cmd|apk search -v}}&lt;br /&gt;
* To list all packages are part of the ACF system: {{cmd|apk search -v &#039;acf*&#039; }}&lt;br /&gt;
* To list all packages that list NTP as part of their description, use the &#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039; option: {{cmd|apk search -v --description &#039;NTP&#039; }}&lt;br /&gt;
&lt;br /&gt;
= Info on Packages =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;info&#039;&#039;&#039; command provides information on the contents of packages, their dependencies, and which files belong to a package.&lt;br /&gt;
&lt;br /&gt;
For a given package, each element can be chosen (for example, &#039;&#039;-w&#039;&#039; to show just the webpage information), or all information displayed with the &#039;&#039;-a&#039;&#039; command.&lt;br /&gt;
&lt;br /&gt;
Example: {{cmd|apk info -a zlib}}&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 description:&#039;&#039;&#039;&lt;br /&gt;
 A compression/decompression Library&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 webpage:&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://zlib.net&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 installed size:&#039;&#039;&#039;&lt;br /&gt;
 94208&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 depends on:&#039;&#039;&#039;&lt;br /&gt;
 libc0.9.32&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 is required by:&#039;&#039;&#039;&lt;br /&gt;
 libcrypto1.0-1.0.0-r0&lt;br /&gt;
 apk-tools-2.0.2-r4&lt;br /&gt;
 openssh-client-5.4_p1-r2&lt;br /&gt;
 openssh-5.4_p1-r2&lt;br /&gt;
 libssl1.0-1.0.0-r0&lt;br /&gt;
 freeswitch-1.0.6-r6&lt;br /&gt;
 atop-1.25-r0 &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 contains:&#039;&#039;&#039;&lt;br /&gt;
 lib/libz.so.1.2.5&lt;br /&gt;
 lib/libz.so.1&lt;br /&gt;
 lib/libz.so &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 triggers:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As shown in the example you can determine&lt;br /&gt;
* The &#039;&#039;&#039;description&#039;&#039;&#039; of the package (&#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;webpage&#039;&#039;&#039; where the application is hosted (&#039;&#039;-w&#039;&#039; or &#039;&#039;--webpage&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;size&#039;&#039;&#039; the package will require once installed (in bytes) (&#039;&#039;-s&#039;&#039; or &#039;&#039;--size&#039;&#039;)&lt;br /&gt;
* What packages are required to use this one  (&#039;&#039;&#039;depends&#039;&#039;&#039;) (&#039;&#039;-R&#039;&#039; or &#039;&#039;--depends&#039;&#039;)&lt;br /&gt;
* What packages require this one to be installed (&#039;&#039;&#039;required by&#039;&#039;&#039;) (&#039;&#039;-r&#039;&#039; or &#039;&#039;--rdepends&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;contents&#039;&#039;&#039; of the package, that is, which files it installs (&#039;&#039;-L&#039;&#039; or &#039;&#039;--contents&#039;&#039;)&lt;br /&gt;
* Any &#039;&#039;&#039;triggers&#039;&#039;&#039; this package sets. (&#039;&#039;-t&#039;&#039; or &#039;&#039;--triggers&#039;&#039;) Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete. For example, doing a depmod once after installing all packages that add kernel modules.&lt;br /&gt;
&lt;br /&gt;
{{Tip|The &#039;&#039;&#039;info&#039;&#039;&#039; command is also useful to determine which package a file belongs to.  For example: {{cmd|apk info --who-owns /sbin/lbu}} will display&lt;br /&gt;
&lt;br /&gt;
 /sbin/lbu is owned by alpine-conf-x.x-rx&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Listing installed packages ==&lt;br /&gt;
&lt;br /&gt;
To list all installed packages, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apk info&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all installed packages in alphabetical order, with a description of each, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apk -vv info|sort&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Additional apk Commands =&lt;br /&gt;
In progress...&lt;br /&gt;
&lt;br /&gt;
= Local Cache =&lt;br /&gt;
&lt;br /&gt;
{{:Local_APK_cache}}&lt;br /&gt;
&lt;br /&gt;
= Advanced APK Usage =&lt;br /&gt;
&lt;br /&gt;
== Holding a specific package back ==&lt;br /&gt;
&lt;br /&gt;
In certain cases, you may want to upgrade a system, but keep a specific package at a back level. It is possible to add &amp;quot;sticky&amp;quot; or versioned dependencies. For instance, to hold the &#039;&#039;asterisk&#039;&#039; package to the 1.6.2 level or lower:&lt;br /&gt;
{{cmd|1=apk add asterisk=1.6.0.21-r0}}&lt;br /&gt;
or&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;lt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
after which a {{cmd|apk upgrade}}&lt;br /&gt;
&lt;br /&gt;
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level&lt;br /&gt;
&lt;br /&gt;
To later upgrade to the current version,&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;gt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13149</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13149"/>
		<updated>2017-02-22T22:42:11Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Behaviour with SSL interception */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Typically the server-side connection is established first, using the information available in the CONNECT request from the client (such as the destination server and port) which allows Squid to spoof a certificate.  The Common Name (CN) will reflect the destination server and the Squid certificate will sign it.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13148</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13148"/>
		<updated>2017-02-22T22:22:07Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* explicit forward proxy */ minor changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  Explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client, typically by issuing a 407 HTTP response.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13147</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13147"/>
		<updated>2017-02-22T22:19:40Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* transparent forward proxy */ minor changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server can be involved in client authentication; this will usually involve redirecting the client to a virtual domain, typically with a 401 HTTP response.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13129</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13129"/>
		<updated>2017-02-01T23:22:46Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Blocking domains */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [http://ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13128</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=13128"/>
		<updated>2017-02-01T23:19:45Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: corrected link to porndomains.acl&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12950</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12950"/>
		<updated>2016-09-14T10:19:12Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Squid crashes after configuring HTTPS interception */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12949</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12949"/>
		<updated>2016-09-14T10:18:43Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: Added &amp;quot;Squid crashes after configuring HTTPS interception&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Squid crashes after configuring HTTPS interception =====&lt;br /&gt;
&lt;br /&gt;
Squid may crash after configuring SSL interception.  The service may report as running, but reviewing listening ports no longer shows Squid listening.&lt;br /&gt;
A review of /var/log/messages may show an error &amp;quot;The ssl_crtd helpers are crashing too rapidly, need help!&amp;quot;&lt;br /&gt;
In this instance, perform the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service squid stop&lt;br /&gt;
rm -rf /var/lib/ssl_db&lt;br /&gt;
/usr/lib/squid3/ssl_crtd -c -s /var/lib/ssl_db &lt;br /&gt;
rc-service squid start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12948</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12948"/>
		<updated>2016-09-14T09:39:34Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: spelling correction only&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation appears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=12835</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=12835"/>
		<updated>2016-06-07T11:27:36Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security consultant from the UK.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=mRCyDw594eo &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=IlXOcWYA_KY &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=r6QR8A9_iFU &#039;Chubrub&#039; by Ed Rush &amp;amp; Optical]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=5hVtvm44V94 &#039;Science&#039; by Ganja Kru]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
* knot: authoritative dns server setup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=How_to_setup_a_Alpine_Linux_mirror&amp;diff=12834</id>
		<title>How to setup a Alpine Linux mirror</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=How_to_setup_a_Alpine_Linux_mirror&amp;diff=12834"/>
		<updated>2016-06-07T11:15:18Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: added darkhttpd configuration&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document describes how to set up an Alpine Linux mirror and make it available via http and rsync.&lt;br /&gt;
&lt;br /&gt;
We will:&lt;br /&gt;
* create the dir where we have the mirror&lt;br /&gt;
* set up a cron job to sync with master mirror every hour&lt;br /&gt;
* set up lighttpd for http access&lt;br /&gt;
* set up rsync so other mirrors can rsync from you&lt;br /&gt;
&lt;br /&gt;
Make sure that you have enough disk space; each v3.x branch has around 20 GiB.&lt;br /&gt;
&lt;br /&gt;
== Setting up the cron job ==&lt;br /&gt;
Install rsync which will be used to sync from the master mirror.&lt;br /&gt;
{{Cmd|apk add rsync}}&lt;br /&gt;
&lt;br /&gt;
Save the following file as &#039;&#039;/etc/periodic/hourly/alpine-mirror&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# make sure we never run 2 rsync at the same time&lt;br /&gt;
lockfile=&amp;quot;/tmp/alpine-mirror.lock&amp;quot;&lt;br /&gt;
if [ -z &amp;quot;$flock&amp;quot; ] ; then&lt;br /&gt;
  exec env flock=1 flock -n $lockfile &amp;quot;$0&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
src=rsync://rsync.alpinelinux.org/alpine/ &lt;br /&gt;
dest=/var/www/localhost/htdocs/alpine/&lt;br /&gt;
&lt;br /&gt;
# uncomment this to exclude old v2.x branches&lt;br /&gt;
#exclude=&amp;quot;--exclude v2.*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
mkdir -p &amp;quot;$dest&amp;quot;&lt;br /&gt;
/usr/bin/rsync \&lt;br /&gt;
        --archive \&lt;br /&gt;
        --update \&lt;br /&gt;
        --hard-links \&lt;br /&gt;
        --delete \&lt;br /&gt;
        --delete-after \&lt;br /&gt;
        --delay-updates \&lt;br /&gt;
        --timeout=600 \&lt;br /&gt;
        $exclude \&lt;br /&gt;
        &amp;quot;$src&amp;quot; &amp;quot;$dest&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make it executable:&lt;br /&gt;
{{Cmd|&amp;lt;nowiki&amp;gt;chmod +x /etc/periodic/hourly/alpine-mirror&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Now it will sync every hour. (given cron runs)&lt;br /&gt;
&lt;br /&gt;
== Setting up HTTP access via lighttpd ==&lt;br /&gt;
&lt;br /&gt;
Install the lighttpd server&lt;br /&gt;
{{Cmd|apk add lighttpd}}&lt;br /&gt;
&lt;br /&gt;
Enable dir listings by uncommenting the following line in &#039;&#039;/etc/lighttpd/lighttpd.conf&#039;&#039;:&lt;br /&gt;
 dir-listing.activate      = &amp;quot;enable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Also set cache-control to force cache revalidate every 30 mins. Uncomment mod_setenv in &#039;&#039;/etc/lighttpd/lighttpd.conf&#039;&#039;:&lt;br /&gt;
 &amp;quot;mod_setenv&amp;quot;,&lt;br /&gt;
&lt;br /&gt;
Add also the following lines to &#039;&#039;/etc/lighttpd/lighttpd.conf&#039;&#039;:&lt;br /&gt;
 setenv.add-response-header += (           &lt;br /&gt;
         &amp;quot;Cache-Control&amp;quot; =&amp;gt; &amp;quot;must-revalidate&amp;quot;&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
Start lighttpd and make it start at boot:&lt;br /&gt;
{{Cmd|rc-service lighttpd start&lt;br /&gt;
rc-update add lighttpd}}&lt;br /&gt;
&lt;br /&gt;
{{Note|You may wish to consider [[Darkhttpd]] as an alternative to [[Lighttpd]]&lt;br /&gt;
&lt;br /&gt;
If so, simply install, start and auto-start the webserver:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd &amp;amp;&amp;amp; rc-service darkhttpd start &amp;amp;&amp;amp; rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
Darkhttpd will, by default, offer directory listings and serve data from /var/www/localhost/htdocs/ &lt;br /&gt;
&lt;br /&gt;
See the main article on [[Darkhttpd]] for more configuration options}}&lt;br /&gt;
&lt;br /&gt;
== Setting up rsyncd ==&lt;br /&gt;
Add the following lines to &#039;&#039;/etc/rsyncd.conf&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[alpine]&lt;br /&gt;
        path = /var/www/localhost/htdocs/alpine&lt;br /&gt;
        comment = My Alpine Linux Mirror&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally set a bandwidth limit in &#039;&#039;/etc/conf.d/rsyncd&#039;&#039;. In this example we limit to 500Kbytes/s (approx 5Mbit/s)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RSYNC_OPTS=&amp;quot;--bwlimit=500&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
[[File:sync.sh]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12522</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=12522"/>
		<updated>2016-03-23T08:39:52Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: added note about CONNECT method&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.  Connections to HTTPS sites through an explicit proxy will use the CONNECT HTTP method.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation apears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=11534</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=11534"/>
		<updated>2015-12-23T15:35:44Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &amp;quot;#dns_defnames on&amp;quot; not &amp;quot;#dns_defnames enabled&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation apears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames on&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11455</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11455"/>
		<updated>2015-11-15T17:22:15Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=mRCyDw594eo &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=IlXOcWYA_KY &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=r6QR8A9_iFU &#039;Chubrub&#039; by Ed Rush &amp;amp; Optical]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=5hVtvm44V94 &#039;Science&#039; by Ganja Kru]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
* knot: authoritative dns server setup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11421</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11421"/>
		<updated>2015-11-13T09:30:01Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=mRCyDw594eo &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=IlXOcWYA_KY &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=r6QR8A9_iFU &#039;Chubrub&#039; by Ed Rush &amp;amp; Optical]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
* knot: authoritative dns server setup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11407</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=11407"/>
		<updated>2015-11-09T11:57:20Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=mRCyDw594eo &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=IlXOcWYA_KY &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
* knot: authoritative dns server setup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10841</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10841"/>
		<updated>2015-05-06T17:45:04Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: replaced yet more &amp;#039;hdoc&amp;#039; with &amp;#039;htdoc&amp;#039; :¬S&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.  &lt;br /&gt;
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;/var/files --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under the server root, by default {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10839</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10839"/>
		<updated>2015-05-06T09:05:07Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.  &lt;br /&gt;
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;/var/files --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under the server root, by default {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10838</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10838"/>
		<updated>2015-05-06T09:03:19Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.  &lt;br /&gt;
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;/var/files --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under the server root, by default {{Path|/var/www/localhost/hdocs}} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under the server root, by default {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10837</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10837"/>
		<updated>2015-05-06T09:01:55Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: extended darkhttpd configuration section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.  &lt;br /&gt;
For example, you might wish to serve files from {{Path|/var/files}} instead, so you can edit the {{Path|/etc/init.d/darkhttpd}} file with an editor of your choice (vi, nano, vim or whatever) and make it like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;/var/files --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under {{Path|/var/www/localhost/hdocs}} &lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10836</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10836"/>
		<updated>2015-05-06T08:37:50Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: edited more paths to document root&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/htdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/htdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under {{Path|/var/www/localhost/hdocs}} &lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10835</id>
		<title>Darkhttpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Darkhttpd&amp;diff=10835"/>
		<updated>2015-05-06T08:35:50Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: corrected path to document root (Thanks Bryan!)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Darkhttpd is a simple, fast HTTP 1.1 web server for static content.  It does not support PHP or CGI etc but is designed to serve static content, which it does very well.  Darkhttpd would be an excellent alternative to [[Lighttpd]] for [[How to setup a Alpine Linux mirror|running an Alpine mirror]]&lt;br /&gt;
    &lt;br /&gt;
For a full list of features see the [http://unix4lyfe.org/darkhttpd/ darkhttpd homepage]&lt;br /&gt;
&lt;br /&gt;
= Install =&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Configure =&lt;br /&gt;
&lt;br /&gt;
Default location of files to serve: {{Path|/var/www/localhost/htdocs}}&lt;br /&gt;
&lt;br /&gt;
Default log path: {{Path|/var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
There&#039;s no configuration file for {{Pkg|darkhttpd}}, everything is controlled from the command line or in our case the OpenRC init file, which is stored in {{Path|/etc/init.d/darkhttpd}} and by default looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /sbin/runscript&lt;br /&gt;
&lt;br /&gt;
description=&amp;quot;darkhttpd web server&amp;quot;&lt;br /&gt;
command=&amp;quot;/usr/bin/darkhttpd&amp;quot;&lt;br /&gt;
command_args=&amp;quot;${document_root:-/var/www/localhost/htdocs} --chroot --daemon --uid darkhttpd --gid www-data --log /var/log/darkhttpd/access.log&amp;quot;&lt;br /&gt;
procname=&amp;quot;darkhttpd&amp;quot;&lt;br /&gt;
pidfile=&amp;quot;&amp;quot;&lt;br /&gt;
stopsig=&amp;quot;SIGTERM&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So by default we will serve pages from {{Path|/var/www/localhost/hdocs}} and darkhttpd will run as a background daemon, [https://en.wikipedia.org/wiki/Chroot chrooted] to {{Path|/var/www/localhost/hdocs}} with a user of &amp;lt;code&amp;gt;darkhttpd&amp;lt;/code&amp;gt; and group of &amp;lt;code&amp;gt;www-data&amp;lt;/code&amp;gt;.&lt;br /&gt;
Logs will go to {{Path|/var/log/darkhttpd/access.log}}.&lt;br /&gt;
The default values have been chosen to provide sane, secure settings. &lt;br /&gt;
&lt;br /&gt;
Change any of these values as you see fit, but it&#039;s a good idea to backup the file before making changes.&lt;br /&gt;
&lt;br /&gt;
For a full list of available options, run: {{Cmd|darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
and amend the &amp;lt;code&amp;gt;command_args&amp;lt;/code&amp;gt; line as you see fit.&lt;br /&gt;
&lt;br /&gt;
= Use =&lt;br /&gt;
&lt;br /&gt;
Filesharing is made easy; simply add your files under {{Path|/var/www/localhost/hdocs}} &lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
Create a test page under {{Path|/var/www/localhost/hdocs}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;this is a test page&amp;quot; &amp;gt; /var/www/localhost/htdocs/index.html}}&lt;br /&gt;
&lt;br /&gt;
{{Note| You don&#039;t have to create a test page; in a working environment darkhttpd will generate a directory listing if no index page is found.}}&lt;br /&gt;
&lt;br /&gt;
Start the daemon: {{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
Output should be something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * Starting darkhttpd ...&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
listening on: http://0.0.0.0:80/&lt;br /&gt;
chrooted to `/var/www/localhost/htdocs&#039;&lt;br /&gt;
set gid to 82&lt;br /&gt;
set uid to 100                                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now point a browser to your darkhttpd server and you should get the index page, or a directory listing if you didn&#039;t create an index page.&lt;br /&gt;
&lt;br /&gt;
Check the logfile: {{Cmd|tail /var/log/darkhttpd/access.log}}&lt;br /&gt;
&lt;br /&gt;
== Controlling darkhttpd status ==&lt;br /&gt;
&lt;br /&gt;
Stop, start and restart the daemon in the usual fashion:&lt;br /&gt;
{{Cmd|rc-service darkhttpd start}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd stop}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service darkhttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Auto-start darkhttpd at boot ==&lt;br /&gt;
&lt;br /&gt;
To add the daemon to the default runlevel so it auto-starts at boot, do: {{Cmd|rc-update add darkhttpd}}&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
* When restarting the daemon you may see an error message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Stopping darkhttpd ...&lt;br /&gt;
/lib/rc/sh/runscript.sh: line 202: can&#039;t create /sys/fs/cgroup/openrc/darkhttpd/tasks: nonexistent directory&lt;br /&gt;
Starting darkhttpd ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This error message appears to be benign and of no consequence so can be ignored.  I can only replicate this error on a VMWare vSphere client.&lt;br /&gt;
&lt;br /&gt;
* If the daemon will not start, ensure you haven&#039;t made a syntax error in the init script.&lt;br /&gt;
&lt;br /&gt;
* Ensure the daemon is running with {{Cmd|rc-status}}&lt;br /&gt;
&lt;br /&gt;
* Make use of the logs to check it is receiving requests.  To do this, run {{Cmd|tail -f /var/log/darkhttpd/access.log}} and then send requests to the web server.  If darkhttpd is receiving the requests, lines will be logged. If you don&#039;t see these lines, perhaps a firewall rule is blocking access to the server or there is a routing issue somewhere?&lt;br /&gt;
Use &#039;Ctrl C&#039; to exit back to the prompt when finished testing.&lt;br /&gt;
&lt;br /&gt;
= man darkhttpd =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v-alpine-server:~# darkhttpd&lt;br /&gt;
darkhttpd/1.9, copyright (c) 2003-2013 Emil Mikulic.&lt;br /&gt;
usage:  darkhttpd /path/to/wwwroot [flags]&lt;br /&gt;
&lt;br /&gt;
flags:  --port number (default: 8080, or 80 if running as root)&lt;br /&gt;
                Specifies which port to listen on for connections.&lt;br /&gt;
&lt;br /&gt;
        --addr ip (default: all)&lt;br /&gt;
                If multiple interfaces are present, specifies&lt;br /&gt;
                which one to bind the listening port to.&lt;br /&gt;
&lt;br /&gt;
        --maxconn number (default: system maximum)&lt;br /&gt;
                Specifies how many concurrent connections to accept.&lt;br /&gt;
&lt;br /&gt;
        --log filename (default: stdout)&lt;br /&gt;
                Specifies which file to append the request log to.&lt;br /&gt;
&lt;br /&gt;
        --chroot (default: don&#039;t chroot)&lt;br /&gt;
                Locks server into wwwroot directory for added security.&lt;br /&gt;
&lt;br /&gt;
        --daemon (default: don&#039;t daemonize)&lt;br /&gt;
                Detach from the controlling terminal and run in the background.&lt;br /&gt;
&lt;br /&gt;
        --index filename (default: index.html)&lt;br /&gt;
                Default file to serve when a directory is requested.&lt;br /&gt;
&lt;br /&gt;
        --mimetypes filename (optional)&lt;br /&gt;
                Parses specified file for extension-MIME associations.&lt;br /&gt;
&lt;br /&gt;
        --uid uid/uname, --gid gid/gname (default: don&#039;t privdrop)&lt;br /&gt;
                Drops privileges to given uid:gid after initialization.&lt;br /&gt;
&lt;br /&gt;
        --pidfile filename (default: no pidfile)&lt;br /&gt;
                Write PID to the specified file.  Note that if you are&lt;br /&gt;
                using --chroot, then the pidfile must be relative to,&lt;br /&gt;
                and inside the wwwroot.&lt;br /&gt;
&lt;br /&gt;
        --no-keepalive&lt;br /&gt;
                Disables HTTP Keep-Alive functionality.&lt;br /&gt;
&lt;br /&gt;
        --forward host url (default: don&#039;t forward)&lt;br /&gt;
                Web forward (301 redirect).&lt;br /&gt;
                Requests to the host are redirected to the corresponding url.&lt;br /&gt;
                The option may be specified multiple times, in which case&lt;br /&gt;
                the host is matched in order of appearance.&lt;br /&gt;
&lt;br /&gt;
        --no-server-id&lt;br /&gt;
                Don&#039;t identify the server type in headers&lt;br /&gt;
                or directory listings.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=10591</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=10591"/>
		<updated>2015-03-25T22:05:41Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Doorway+Gridlock+Echo+Remix/aGkez?src=5 &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/No+Test/3GHSp1?src=5 &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
* knot: authoritative dns server setup&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10537</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10537"/>
		<updated>2015-03-10T11:22:51Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* FREAK attack (CVE-2015-0204) - added link to https://freakattack.com/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probably a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Ultimately when choosing SSL/TLS ciphers it is the usual chose of security or usability?  Increasing one usually decreases the other.  Nonetheless, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== POODLE attack (CVE-2014-3566) ===&lt;br /&gt;
&lt;br /&gt;
In light of the recent [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 POODLE] findings, it&#039;s advisable to wherever possible turn off support for SSLv3.  This is quite simple, you can just append the following to your cipher list to explicitly disable SSLv3 support:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!SSLv3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== FREAK attack (CVE-2015-0204) ===&lt;br /&gt;
&lt;br /&gt;
To prevent the so called [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-0204 FREAK] attack, keep your SSL library up to date, and do not offer support for export grade ciphers.&lt;br /&gt;
&lt;br /&gt;
There&#039;s multiple ways to do this, like turning off export cipher support in the cipher list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!EXPORT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although now might be a good time to review the cipher list in use, and use a stronger, explicit set like the one from the Perfect Forward Secrecy section, or another example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also see https://freakattack.com/&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10536</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10536"/>
		<updated>2015-03-10T11:18:58Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /*Added FREAK attack reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probably a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Ultimately when choosing SSL/TLS ciphers it is the usual chose of security or usability?  Increasing one usually decreases the other.  Nonetheless, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== POODLE attack (CVE-2014-3566) ===&lt;br /&gt;
&lt;br /&gt;
In light of the recent [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 POODLE] findings, it&#039;s advisable to wherever possible turn off support for SSLv3.  This is quite simple, you can just append the following to your cipher list to explicitly disable SSLv3 support:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!SSLv3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== FREAK attack (CVE-2015-0204) ===&lt;br /&gt;
&lt;br /&gt;
To prevent the so called [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-0204 FREAK] attack, keep your SSL library up to date, and do not offer support for export grade ciphers.&lt;br /&gt;
&lt;br /&gt;
There&#039;s multiple ways to do this, like turning off export cipher support in the cipher list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!EXPORT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although now might be a good time to review the cipher list in use, and use a stronger, explicit set like the one from the Perfect Forward Secrecy section, or another example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10528</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10528"/>
		<updated>2015-02-23T12:13:04Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: removed RC4 from PFS section (rc4 not recommended) and removed source link (unnecessary)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probably a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Ultimately when choosing SSL/TLS ciphers it is the usual chose of security or usability?  Increasing one usually decreases the other.  Nonetheless, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== POODLE attack (CVE-2014-3566) ===&lt;br /&gt;
&lt;br /&gt;
In light of the recent [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 POODLE] findings, it&#039;s advisable to wherever possible turn off support for SSLv3.  This is quite simple, you can just append the following to your cipher list to explicitly disable SSLv3 support:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!SSLv3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux:FAQ&amp;diff=10244</id>
		<title>Alpine Linux:FAQ</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Linux:FAQ&amp;diff=10244"/>
		<updated>2015-01-02T11:30:34Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* My cron jobs don&amp;#039;t run? */  amended &amp;quot;-t&amp;quot; to &amp;quot;--test&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:filetypes.svg|64px|left|link=]]&lt;br /&gt;
This is a list of &#039;&#039;&#039;frequently asked questions&#039;&#039;&#039; about Alpine Linux.&amp;lt;br&amp;gt;&lt;br /&gt;
If your question is not answered on this page, use the search box above to find work in progress pages not linked here, or in case of no answer, edit this page and write down your question.&lt;br /&gt;
{{Tip| Prepare your question. Think it through. Make it simple and understandable.}} &lt;br /&gt;
&lt;br /&gt;
=General=&lt;br /&gt;
&lt;br /&gt;
To get oriented and learn what makes our distribution distinctive, see the [http://alpinelinux.org/about About page] or [[Alpine Linux:Overview|our more detailed overview]].&lt;br /&gt;
&lt;br /&gt;
== I have found a bug, where can I report it? ==&lt;br /&gt;
You can report it on the [http://bugs.alpinelinux.org/ bugtracker].&lt;br /&gt;
&lt;br /&gt;
== Are there any details about the releases available? ==&lt;br /&gt;
Yes, please check the [[Alpine Linux:Releases|Releases]] page.&lt;br /&gt;
&lt;br /&gt;
== Alpine freezes during boot from Compact Flash, how can I fix? ==&lt;br /&gt;
Most Compact Flash card readers do not support proper DMA.&amp;lt;br&amp;gt;&lt;br /&gt;
You should append &#039;&#039;&#039;nodma&#039;&#039;&#039; to the &#039;&#039;append&#039;&#039; line in {{path|syslinux.cfg}}.&lt;br /&gt;
&lt;br /&gt;
== How can I contribute? ==&lt;br /&gt;
You can contribute by:&lt;br /&gt;
* using the software and giving feedback&lt;br /&gt;
* by documenting your [http://www.alpinelinux.org Alpine Linux] experiences on this [[Main_Page|wiki]]&lt;br /&gt;
* in many other ways&lt;br /&gt;
Please visit [[Contribute|Contribute page]] to read more about this topic.&lt;br /&gt;
&lt;br /&gt;
Your contributions are highly appreciated.&lt;br /&gt;
&lt;br /&gt;
== How do I remove the CDROM? ==&lt;br /&gt;
Since the modloop loopback device is on CDROM you cannot just run &#039;&#039;eject&#039;&#039;. You need to unmount the modloop first.&amp;lt;br&amp;gt;&lt;br /&gt;
Unmounting both the modloop and the cdrom in one step can be done by executing:&lt;br /&gt;
{{cmd|/etc/init.d/modloop stop}}&lt;br /&gt;
&lt;br /&gt;
Then it&#039;s possible to eject the cdrom:&lt;br /&gt;
{{cmd|eject}}&lt;br /&gt;
&lt;br /&gt;
== Why don&#039;t I have man pages or where is the &#039;man&#039; command? ==&lt;br /&gt;
The {{pkg|man}} command and man pages are not installed by default.&lt;br /&gt;
&lt;br /&gt;
* First, install the {{pkg|man}} package:&lt;br /&gt;
: {{Cmd|apk add man}}&lt;br /&gt;
* Once that&#039;s done, install the documentation for the packages that you require man pages for:&amp;lt;br /&amp;gt;(Keep in mind, however, it&#039;s possible that not all packages will have a corresponding documentation package.)&lt;br /&gt;
: {{Cmd|apk add &amp;lt;pkg&amp;gt;-doc}}&lt;br /&gt;
: For example, say you installed {{pkg|iptables}} and you now require its {{pkg|man}} pages:&lt;br /&gt;
: {{Cmd|apk add iptables-doc}}&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
In our example above, we installed the man pages (and other documentation) for iptables. We can now read it:&lt;br /&gt;
{{Cmd|man iptables}}&lt;br /&gt;
&lt;br /&gt;
==Booting Alpine on an HP ML350 G6==&lt;br /&gt;
{{Note|This &#039;Booting Alpine on an HP ML350 G6&#039; section, only applies to [http://www.alpinelinux.org/ Alpine Linux] 1.9.3 and earlier.}}&lt;br /&gt;
[http://bugs.alpinelinux.org/issues/228 Ticket 228] on [http://bugs.alpinelinux.org/ bugs.alpinelinux.org] includes a patch that disables the kernel module hpwdt by default.&lt;br /&gt;
&lt;br /&gt;
Details: Kernel module for HP Watchdog Timer causes issues during boot.  Solution is to create an overlay (ie {{path|hpwdt.apkovl.tar.gz}}) containing {{path|/etc/modprobe.d/hpwdt}} (which contains &amp;quot;blacklist hpwdt&amp;quot;), place that on some removable media (ie USB key) and insert that during boot process.  This will insure that the offending module doesn&#039;t load and that the server will boot properly.&lt;br /&gt;
&lt;br /&gt;
==My cron jobs don&#039;t run?==&lt;br /&gt;
The cron daemon is started automatically on system boot and executes the scripts placed in the folders under {{path|/etc/periodic}} - there&#039;s a {{path|15min}} folder, plus ones for {{path|hourly}}, {{path|daily}}, {{path|weekly}} and {{path|monthly}} scripts.&lt;br /&gt;
&lt;br /&gt;
You can check whether your scripts are likely to run using the command:&lt;br /&gt;
&lt;br /&gt;
: {{cmd|run-parts --test /etc/periodic/[foldername]}} - for example: &#039;&#039;run-parts -t /etc/periodic/15min&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command will tell you what should run but will not actually execute the scripts.&lt;br /&gt;
&lt;br /&gt;
If the results of the test are not as expected, check the following:&lt;br /&gt;
&lt;br /&gt;
* Make sure the script is executable - if unsure, issue the command : {{cmd|chmod a+x [scriptname]}}&lt;br /&gt;
* Make sure the first line of your script is :&amp;lt;pre&amp;gt;#!/bin/sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Do not put file extensions on your script names - this stops them from working; for example: {{path|myscript}}  will run, but {{path|myscript.sh}} won&#039;t&lt;br /&gt;
&lt;br /&gt;
== What is the difference between edge and stable releases? ==&lt;br /&gt;
Stable releases are just what they sound like: initially a point-in-time snapshot of the package archives, but then maintained with bugfixes only in order to keep a stable environment.&lt;br /&gt;
&lt;br /&gt;
[[Edge]] is more of a rolling-release, with the latest and greatest packages available in the online repositories.&amp;lt;br&amp;gt;&lt;br /&gt;
Occasionally, snapshot ISO images of the then-current state of [[edge]] are made and are available for download.&amp;lt;br&amp;gt;&lt;br /&gt;
Typically these are made when there are major kernel upgrades or package upgrades that require initramfs rebuilds.&lt;br /&gt;
&lt;br /&gt;
== What kind of release of Alpine Linux are available? ==&lt;br /&gt;
Please check the [[Alpine_Linux:Releases|Releases]] page for more information.&lt;br /&gt;
&lt;br /&gt;
=Setup=&lt;br /&gt;
&lt;br /&gt;
== What is the difference between &#039;sys&#039;, &#039;data&#039;, and &#039;diskless&#039; installs when running setup-alpine (or setup-disk)? ==&lt;br /&gt;
&#039;&#039;&#039;sys:&#039;&#039;&#039; This mode is a traditional disk install. The following partitions will be created on the disk: /boot, / (filesystem root) and swap.&amp;lt;br&amp;gt;&lt;br /&gt;
This mode may be used for development boxes, desktops, virtual servers, etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;data:&#039;&#039;&#039; This mode uses your disk(s) for data storage, not for the operating system.  Only /var is created on disk.  The system itself will run from tmpfs (RAM).  &lt;br /&gt;
&lt;br /&gt;
Use this mode if you only want to use the disk(s) for a mailspool, databases, logs, etc.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;diskless:&#039;&#039;&#039; No disks are to be used.  [[Alpine local backup]] may still be used in this mode.&lt;br /&gt;
&lt;br /&gt;
== How can I install a custom firmware in a diskless system? ==&lt;br /&gt;
&lt;br /&gt;
The modules and firmware are both special images which are mounted as read-only.&amp;lt;br&amp;gt;&lt;br /&gt;
To fix this issue you can copy the firmware directory to your writeable media (cf/usb) and copy your custom firmware to it.&amp;lt;br&amp;gt;&lt;br /&gt;
After reboot Alpine should automatically use the directory on your local storage instead of the loopback device.&lt;br /&gt;
&lt;br /&gt;
=Audio=&lt;br /&gt;
&lt;br /&gt;
== How do I play my .ogg/.mp3 files? ==&lt;br /&gt;
First, the sound card should be recognized (you must have {{path|/dev/snd/*****}} files)&lt;br /&gt;
&lt;br /&gt;
{{pkg|sox}}, {{pkg|mpg123}}, etc all use the oss sound driver, while Alpine uses ALSA drivers.&amp;lt;br&amp;gt;&lt;br /&gt;
So you need to load the snd-pcm-oss compatibility module.&amp;lt;br&amp;gt;&lt;br /&gt;
While you&#039;re at it, you might need {{pkg|aumix}} to turn up the sound volume&lt;br /&gt;
{{cmd|echo snd-pcm-oss &amp;gt;&amp;gt; /etc/modules&lt;br /&gt;
modprobe snd-pcm-oss &lt;br /&gt;
apk_add aumix sox&lt;br /&gt;
aumix (set volume settings)&lt;br /&gt;
play really_cool_song.mp3}}&lt;br /&gt;
&lt;br /&gt;
= Time and timezones =&lt;br /&gt;
&lt;br /&gt;
== How do I set the local timezone? ==&lt;br /&gt;
&lt;br /&gt;
Starting in Alpine 2.2, setting the timezone can be done through the [[Setup-alpine|setup-alpine]] script, and no manual settings should be necessary.&amp;lt;br&amp;gt;&lt;br /&gt;
If you wish to edit the timezone after installation, run the [[Alpine_setup_scripts|setup-timezone]] script.&lt;br /&gt;
&lt;br /&gt;
However, if you are using a previous version, please use the following steps:&lt;br /&gt;
&lt;br /&gt;
 /etc/timezone and the whole zoneinfo directory tree are not supported.&lt;br /&gt;
 To set the timezone, set the TZ environment variable as specified in&lt;br /&gt;
 http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html&lt;br /&gt;
 or you may also create an /etc/TZ file of a single line, ending with a&lt;br /&gt;
 newline, containing the TZ setting.  For example&lt;br /&gt;
 echo CST6CDT &amp;gt; /etc/TZ&lt;br /&gt;
&#039;&#039;Source: http://www.uclibc.org/downloads/Glibc_vs_uClibc_Differences.txt&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For more information, see how other uClibc-based distributions do this:&lt;br /&gt;
* http://leaf.sourceforge.net/doc/buci-tz3.html&lt;br /&gt;
* http://www.sonoracomm.com/index.php?option=com_content&amp;amp;task=view&amp;amp;id=107&amp;amp;Itemid=32&lt;br /&gt;
&lt;br /&gt;
For a more complete list of timezones, please see: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones&lt;br /&gt;
&lt;br /&gt;
== OpenNTPD reports an error with &amp;quot;adjtime&amp;quot; ==&lt;br /&gt;
Your log contains something like:&lt;br /&gt;
 reply from 85.214.86.126: offset 865033148.784255 delay 0.055466, next query 32s&lt;br /&gt;
 reply from 202.150.212.24: offset 865033148.779314 delay 0.400771, next query 3s&lt;br /&gt;
 adjusting local clock by 865033148.779835s                                      &lt;br /&gt;
 adjtime failed: Invalid argument    &lt;br /&gt;
&lt;br /&gt;
{{pkg|openntpd}} is supposed to make small adjustments in the time without causing time jumps.&amp;lt;br&amp;gt;&lt;br /&gt;
If the adjustment is too big then something is clearly wrong and ntpd gives up. (its actually adjtime(3) that has a limit on how big adjustments are allowed)&lt;br /&gt;
&lt;br /&gt;
You can make ntpd set the time at startup by adding &#039;&#039;-s&#039;&#039; option to ntpd. This is done by setting &#039;&#039;&#039;NTPD_OPTS=&amp;quot;-s&amp;quot;&#039;&#039;&#039; in {{path|/etc/conf.d/ntpd}}.&lt;br /&gt;
&lt;br /&gt;
== Using a cron job to keep the time in sync ==&lt;br /&gt;
Add the following to {{path|/etc/periodic/daily}} (or use another folder under the {{path|/etc/periodic}} heirarchy if you want to run the script more/less frequently)&lt;br /&gt;
&lt;br /&gt;
Example: file called {{path|do-ntp}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
ntpd -d -q -n -p uk.pool.ntp.org&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This queries the uk time server pool - you can modify this to suit your localisation, or just use &#039;&#039;pool.ntp.org&#039;&#039;. More info here: [http://www.pool.ntp.org/zone/@ http://www.pool.ntp.org/zone/@]&lt;br /&gt;
&lt;br /&gt;
== Windows clients reports an error when trying to sync ==&lt;br /&gt;
{{pkg|openntpd}} needs to run for a while before it is satisfied it is in sync.&lt;br /&gt;
Until then it will set a flag &amp;quot;clock not synchronized&amp;quot; and Windows will report an error while trying to sync with your {{pkg|openntpd}} server.&lt;br /&gt;
&lt;br /&gt;
Only thing to do is wait, do something else for 15-20mins and then check.&lt;br /&gt;
&lt;br /&gt;
= Packages =&lt;br /&gt;
== Can you build an apk package for ...? ==&lt;br /&gt;
Yes, we probably can.&amp;lt;br&amp;gt;&lt;br /&gt;
Please create an [http://redmine.alpinelinux.org/projects/alpine/issues/new issue] in the [http://bugs.alpinelinux.org bugtracker]. Mark it as &amp;quot;feature&amp;quot; and include a short description (one-line), an url for the home page, and an url for the source package.&lt;br /&gt;
&lt;br /&gt;
== How can I build my own package? ==&lt;br /&gt;
Please see the [[Creating an Alpine package]] page.&lt;br /&gt;
&lt;br /&gt;
== WARNING: Ignoring APKINDEX.xxxx.tar.gz ==&lt;br /&gt;
If you get &amp;lt;code&amp;gt;WARNING: Ignoring APKINDEX.xxxx.tar.gz: No such file or directory&amp;lt;/code&amp;gt; while running package related tools, check your {{path|/etc/apk/repositories}} file if an entry points to {{path|.../v2.4/testing/}}. This directory is gone.&lt;br /&gt;
&lt;br /&gt;
To check the content of the repositories file&lt;br /&gt;
{{Cmd|cat /etc/apk/repositories}}&lt;br /&gt;
&lt;br /&gt;
or &lt;br /&gt;
{{Cmd|setup-apkrepos}}&lt;br /&gt;
&lt;br /&gt;
= Dynamic DNS =&lt;br /&gt;
== How do I schedule a regular dynamic DNS update? ==&lt;br /&gt;
You&#039;ll want to install the {{pkg|ez-ipupdate}} package:&lt;br /&gt;
{{cmd|apk add ez-ipupdate}}&lt;br /&gt;
&lt;br /&gt;
After that, create a new file at {{path|/etc/ezipupdate.conf}} with the contents similar to:&lt;br /&gt;
 service-type=dyndns&lt;br /&gt;
 user=myusername:mypassword&lt;br /&gt;
 interface=eth1&lt;br /&gt;
 host=myhostname.dyndns.org&lt;br /&gt;
&lt;br /&gt;
Make the new ip cache directory:&lt;br /&gt;
{{cmd|mkdir /var/cache/ez-ipupdate&lt;br /&gt;
lbu add /var/cache/ez-ipupdate}}&lt;br /&gt;
&lt;br /&gt;
Then schedule a new cron job with this command:&lt;br /&gt;
{{cmd|echo &amp;gt;&amp;gt; /var/log/ez-ipupdate &amp;amp;&amp;amp; /bin/date &amp;gt;&amp;gt; /var/log/ez-ipupdate &amp;amp;&amp;amp; ez-ipupdate --config /etc/ez-ipupdate.conf -f -F /var/run/ez-ipupdate.pid --cache-file /var/cache/ez-ipupdate/ipcache --quiet &amp;gt;&amp;gt; /var/log/ez-ipupdate 2&amp;gt;&amp;amp;1}}&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to backup your settings!&lt;br /&gt;
{{cmd|lbu ci}}&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Entropy_and_randomness&amp;diff=10235</id>
		<title>Entropy and randomness</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Entropy_and_randomness&amp;diff=10235"/>
		<updated>2014-12-10T13:52:24Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Entropy_%28computing%29 Entropy] is described as &#039;a numerical measure of the uncertainty of an outcome&#039; and is often associated with chaos or disorder however is often more simply called [https://en.wikipedia.org/wiki/Randomness randomness].&lt;br /&gt;
&lt;br /&gt;
It is important for a secure operating system to have sufficient quantities of entropy available for various crypotographic and non-cryptographic purposes, such as:&lt;br /&gt;
&lt;br /&gt;
* Generation of cryptographic keys&lt;br /&gt;
&lt;br /&gt;
* Address Space Layout Randomisation ([http://en.wikipedia.org/wiki/PaX#Address_space_layout_randomization ASLR]) - used by default in Alpine of course ;)&lt;br /&gt;
&lt;br /&gt;
* TCP port randomisation ([https://en.wikipedia.org/wiki/Network_address_translation NAT], outbound connection)&lt;br /&gt;
&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Reliable_transmission TCP sequence number] selection (see [https://en.wikipedia.org/wiki/TCP_sequence_prediction_attack this too)]&lt;br /&gt;
&lt;br /&gt;
* Writing random files for testing network functionality and throughput&lt;br /&gt;
&lt;br /&gt;
* Overwriting hard disks prior to reuse or resale or encryption&lt;br /&gt;
&lt;br /&gt;
Entropy is contained within a &#039;&#039;&#039;pool&#039;&#039;&#039;, which draws its entropy from various &#039;&#039;&#039;sources&#039;&#039;&#039;. To view the current amount of entropy in the pool:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|more /proc/sys/kernel/random/entropy_avail}}&lt;br /&gt;
&lt;br /&gt;
To view the maximum limit of entropy that the pool can hold:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|more /proc/sys/kernel/random/poolsize}}&lt;br /&gt;
&lt;br /&gt;
On a standard system the limit is 4096 bits (512 bytes).  The [https://grsecurity.net/ gr-sec] patch used on Alpine increases this limit to 16384 bits (2048 bytes).&lt;br /&gt;
Entropy is added to the pool in bits from various sources, &amp;quot;the relative number of unknown bits per event is roughly 8/keyboard, 12/mouse, 3/disk, 4/interrupt&amp;quot; [http://www.issihosts.com/haveged/history.html#intro source] meaning that on a headless server (without mouse and keyboard attached), which ironically is often a system requiring the most entropy, entropy generation is somewhat limited.&lt;br /&gt;
&lt;br /&gt;
The entropy from the pool can be accessed in two ways by default:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/random&#039;&#039;&#039; - This is a [https://en.wikipedia.org/wiki/Blocking_%28computing%29 blocking] resource, so it will use available entropy from the pool.  If more entropy is required than is available, the process will wait until more entropy is available in the pool.  Due to this behaviour, /dev/random is best used where small amounts of high quality randomness are required, such as for cryptographic keys.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/urandom&#039;&#039;&#039; - Is a non-blocking resource. It uses a seed value from the same entropy pool as /dev/random and therefore, if little entropy is available in the pool, it is recommended not to use /dev/urandom until more entropy is made available in the pool.  It runs the seed value through an algorithm and so is a [http://en.wikipedia.org/wiki/Pseudo-random_number_generator pseudo-random number generator], operating much faster than /dev/random.  /dev/urandom is best used for non-cryptographic purposes such as overwriting disks.&lt;br /&gt;
&lt;br /&gt;
Writing to /dev/random or /dev/urandom will update the entropy pool with the data written, but this will not result in a higher entropy count.  This means that it will impact the contents read from both files, but it will not make reads from /dev/random faster.&lt;br /&gt;
For more information see the [http://linux.die.net/man/4/random random manpage]&lt;br /&gt;
&lt;br /&gt;
It is generally recommended wherever entropy is used heavily to supply additional entropy sources; some possibilities are below.  Adding more sources of entropy to feed into the pool is a good idea.  It makes an attackers job more difficult, because there will be more sources they have to gain control over (or at the very least observe at source), and adding more sources of entropy, even weak ones, can only result in higher entropy.&lt;br /&gt;
&lt;br /&gt;
If you are desperate for more entropy and are working on a headless server with no internet connection, you could try generating some via disk activity.  Just don&#039;t expect any miracles!  Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dd if=/dev/zero of=/var/tmp/tempfile bs=1M count=200 &amp;amp;&amp;amp; find / -size +1k &amp;amp;&amp;amp; ls -R / &amp;amp;&amp;amp; rm /var/tmp/tempfile &amp;amp;&amp;amp; sync&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server is a &#039;run-from-ram&#039; setup and so you have no disks to create churn but require more entropy, it is strongly recommended to add alternative entropy sources as discussed below.&lt;br /&gt;
&lt;br /&gt;
== Alternative/Additional entropy sources ==&lt;br /&gt;
&lt;br /&gt;
=== Haveged ===&lt;br /&gt;
&lt;br /&gt;
[http://www.issihosts.com/haveged/ Haveged] generates entropy based on [http://www.issihosts.com/haveged/flutter.html CPU flutter].  The entropy is buffered and fed into the entropy pool when write_wakeup_threshold is reached.  Write a value (the number of bits) to it if you wish to change it: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;1024&amp;quot; &amp;gt; /proc/sys/kernel/random/write_wakeup_threshold}}&lt;br /&gt;
&lt;br /&gt;
Or change it via haveged:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|haveged -w 1024}}&lt;br /&gt;
&lt;br /&gt;
Install [http://alpinelinux.org/apk/main/x86_64/haveged haveged], then start and set to autostart at boot:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk -U add haveged &amp;amp;&amp;amp; rc-service haveged start &amp;amp;&amp;amp; rc-update add haveged}}&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/haveged Further configuration] is possible however the defaults should work fine out of the box. &lt;br /&gt;
&lt;br /&gt;
=== Other possibilities ===&lt;br /&gt;
&lt;br /&gt;
Some other possibilites for entropy generation are:&lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/te/ timer entropy daemon] -  should provide on-demand entropy based on variances in timings of sleep command.&lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/ved/ video entropy daemon] - requires a video4linux-device, gathers entropy by taking a couple of images and calculating the differences and then the entropy of that.  Can be run on demand or as a cron job. &lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/aed/ audio entropy daemon] - requires alsa development libraries and an audio device.  Generates entropy by reading from audio device and de-baising data.&lt;br /&gt;
&lt;br /&gt;
*[http://vladz.devzero.fr/guchaos.php GUChaos] - &amp;quot;Give Us Chaos&amp;quot; provides on-demand entropy, by retrieving random blocks of bytes from the [http://www.random.org/ Random.org] website, and transforms them with a [http://en.wikipedia.org/wiki/Substitution_cipher polynumeric substitution cipher] before adding them to /dev/random until the entropy pool is filled.&lt;br /&gt;
&lt;br /&gt;
and hardware entropy generators such as: &lt;br /&gt;
&lt;br /&gt;
*[http://www.entropykey.co.uk/ Entropy Key] - USB hardware entropy generator&lt;br /&gt;
&lt;br /&gt;
It is also possible to replace /dev/random with [http://egd.sourceforge.net/ EGD, the Entropy Gathering Daemon], or to use this on systems that are not able to support /dev/random.  However, this is not required (or recommended) under normal circumstances.&lt;br /&gt;
&lt;br /&gt;
== Testing entropy with ENT ==&lt;br /&gt;
&lt;br /&gt;
It is possible to [http://en.wikipedia.org/wiki/Randomness_test test] entropy to see how statistically random it is.  Generally, such tests only reveal part of the picture, since some numbers can pass statistical entropy tests whilst they are not actually random.  Failing a statistical randomness test is not a good indicator of course!&lt;br /&gt;
&lt;br /&gt;
Make a folder for testing, and get hold of [http://www.fourmilab.ch/random/ ENT]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /tmp/test/make&lt;br /&gt;
cd /tmp/test/make&lt;br /&gt;
wget http://www.fourmilab.ch/random/random.zip&lt;br /&gt;
unzip random.zip&lt;br /&gt;
make&lt;br /&gt;
mv ./ent /tmp/test/&lt;br /&gt;
cd /tmp/test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create some random data.  In this example we read from /dev/urandom:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dd if=/dev/urandom of=/tmp/test/urandomfile bs=1 count=16384&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the ENT test against it:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./ent /tmp/test/urandomfile}}&lt;br /&gt;
&lt;br /&gt;
Try the same test whilst treating the data as a stream of bits and printing an account of character occurrences:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./ent -b -c /tmp/test/urandomfile}} &lt;br /&gt;
&lt;br /&gt;
Note any differences against the previous test. &lt;br /&gt;
 &lt;br /&gt;
I propose also generating larger streams of data (10&#039;s or 100&#039;s of MB) and testing against this too.  Any repeating data or patterns (caused by a small/poor seed value for instance) will make spotting any weaknesses and a lack of randomness much easier across large amounts of data than across small amounts.&lt;br /&gt;
&lt;br /&gt;
I also suggest running the test against known non-random files, so you may see that some tests show that such a file can have some characteristics of a random file, whilst completely failing other randomness tests.&lt;br /&gt;
&lt;br /&gt;
Finally, once you are done testing with ENT, it&#039;s good practice to delete the working folder:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rm -r /tmp/test/}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other tests ===&lt;br /&gt;
&lt;br /&gt;
Other tests include [http://www.stat.fsu.edu/pub/diehard/ diehard] and [http://www.phy.duke.edu/~rgb/General/dieharder.php dieharder]&lt;br /&gt;
&lt;br /&gt;
== Further reading ==&lt;br /&gt;
&lt;br /&gt;
[http://rsmith.home.xs4all.nl/howto/fun-with-encryption-and-randomness.html visualising randomness]&lt;br /&gt;
&lt;br /&gt;
[http://www.linuxfromscratch.org/hints/downloads/files/entropy.txt linux from scratch]&lt;br /&gt;
&lt;br /&gt;
[http://blog.cloudflare.com/ensuring-randomness-with-linuxs-random-number-generator Cloudflare]&lt;br /&gt;
&lt;br /&gt;
[https://tools.ietf.org/html/rfc4086 RFC 4086 - Randomness Requirements for Security]&lt;br /&gt;
&lt;br /&gt;
[https://calomel.org/entropy_random_number_generators.html calomel.org]&lt;br /&gt;
&lt;br /&gt;
[http://www.av8n.com/turbid/paper/turbid.htm Turbid]&lt;br /&gt;
&lt;br /&gt;
[http://blog.cryptographyengineering.com/2012/02/random-number-generation-illustrated.html Random number generation: An illustrated primer]&lt;br /&gt;
&lt;br /&gt;
[https://factorable.net/weakkeys12.extended.pdf Mining Your Ps and Qs: Detection of Widespread Weak Keys in Network Devices, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://www.pinkas.net/PAPERS/gpr06.pdf  Analysis of the Linux Random Number Generator, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://cryptome.org/2014/03/eat-entropy-have-it.pdf How to Eat Your Entropy and Have it Too — Optimal Recovery Strategies for Compromised RNGs, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://eprint.iacr.org/2013/338.pdf Security Analysis of Pseudo-Random Number Generators with Input: /dev/random is not Robust, PDF]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=SLiM&amp;diff=10220</id>
		<title>SLiM</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=SLiM&amp;diff=10220"/>
		<updated>2014-11-05T14:57:14Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: added warning that SLiM appears to be abandoned&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://slim.berlios.de/index.php SLiM] is a Simple Login Manager (also known as a display manager) which is lightweight and simple to configure.&lt;br /&gt;
&lt;br /&gt;
{{Warning|The SLiM project appears to have been abandoned and the [http://slim.berlios.de/ project homepage] is down}}&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
&lt;br /&gt;
Simply add the {{Pkg|slim}} package with:&lt;br /&gt;
{{Cmd|apk add slim}}&lt;br /&gt;
I should imagine you&#039;d also want some kind of desktop installed too, like [[Gnome Setup|Gnome]] or [[XFCE Setup|XFCE]]&lt;br /&gt;
&lt;br /&gt;
== Configure &amp;amp; Test ==&lt;br /&gt;
&lt;br /&gt;
The SLiM configuration file is at &amp;lt;code&amp;gt;/etc/slim.conf&amp;lt;/code&amp;gt; and it is heavily commented, so I&#039;ll not add any info about it here unless asked to (in the discussion function for instance).  Before making any changes it is recommended to backup the default configuration file with:&lt;br /&gt;
{{Cmd|cp /etc/slim.conf /etc/slim.conf.original}}&lt;br /&gt;
&lt;br /&gt;
Then you can modify &amp;lt;code&amp;gt;/etc/slim.conf&amp;lt;/code&amp;gt; and easily copy the default configuration back if you run into trouble:&lt;br /&gt;
{{Cmd|cp /etc/slim.conf.original /etc/slim.conf}}&lt;br /&gt;
&lt;br /&gt;
To immediately test slim, do {{Cmd|rc-service slim start}} and you should be presented with a login screen, branded for Alpine linux!&lt;br /&gt;
&lt;br /&gt;
Login with your normal user credentials (avoid using a desktop as root) and you should reach your desktop.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve tested it works, start SLiM at the default runlevel:&lt;br /&gt;
{{Cmd|rc-update add slim}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note: You should disable any other display manager you have running&amp;lt;/b&amp;gt; to prevent them both launching.  For example, to prevent lxdm from starting at boot use:&lt;br /&gt;
{{Cmd|rc-update del lxdm}}&lt;br /&gt;
&lt;br /&gt;
== Extra Login Commands ==&lt;br /&gt;
When on the SLiM login screen, you can use:&lt;br /&gt;
* &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt; as a username to return to a shell prompt&lt;br /&gt;
* &amp;lt;code&amp;gt;reboot&amp;lt;/code&amp;gt; as a username and the root password to reboot the machine&lt;br /&gt;
* &amp;lt;code&amp;gt;halt&amp;lt;/code&amp;gt; as a username and the root password to power down the machine&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
If you are using a .xinitrc file (usually located at &amp;lt;code&amp;gt;~/.xinitrc&amp;lt;/code&amp;gt;, slim will read from this and you will need to ensure you have a line to execute your desktop environment.  This is usually the last line of the file.  For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;....&lt;br /&gt;
exec startxfce4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if you are using an [[XFCE Setup|XFCE desktop]], or:&lt;br /&gt;
&amp;lt;pre&amp;gt;....&lt;br /&gt;
exec gnome-session&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
if using [[Gnome Setup|Gnome]].&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t do this, or you make a mistake with your typing, you&#039;ll probably get an error like &amp;lt;code&amp;gt;failed to execute login command&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Themes ==&lt;br /&gt;
&lt;br /&gt;
Simply add the {{Pkg|slim-theme}} package with:&lt;br /&gt;
{{Cmd|apk add slim-themes}}&lt;br /&gt;
&lt;br /&gt;
All theme which are available on your system are located at &amp;lt;code&amp;gt;/usr/share/slim/themes&amp;lt;/code&amp;gt;&lt;br /&gt;
{{Cmd|ls /usr/share/slim/themes}}&lt;br /&gt;
&lt;br /&gt;
You need to modify &amp;lt;code&amp;gt;/etc/slim.conf&amp;lt;/code&amp;gt; to change the theme:&lt;br /&gt;
{{Cmd|sudo vi /etc/slim.conf}}&lt;br /&gt;
&lt;br /&gt;
Search for &amp;lt;code&amp;gt;current_theme&amp;lt;/code&amp;gt; and choose one of the available themes.&lt;br /&gt;
&lt;br /&gt;
== Further Information ==&lt;br /&gt;
&lt;br /&gt;
* [http://slim.berlios.de/index.php SLiM Homepage]&lt;br /&gt;
* [http://slim.berlios.de/manual.php SLiM Manual]&lt;br /&gt;
* [https://wiki.archlinux.org/index.php/SLiM Arch Linux wiki entry]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10206</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10206"/>
		<updated>2014-10-21T09:32:25Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: minor spelling corrections after added lighttpd poodle vulnerability section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probably a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Ultimately when choosing SSL/TLS ciphers it is the usual chose of security or usability?  Increasing one usually decreases the other.  Nonetheless, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://raymii.org/s/tutorials/Pass_the_SSL_Labs_Test_on_Lighttpd_%28Mitigate_the_CRIME_and_BEAST_attack_-_Disable_SSLv2_-_Enable_PFS%29.html Source]&lt;br /&gt;
&lt;br /&gt;
=== POODLE attack (CVE-2014-3566) ===&lt;br /&gt;
&lt;br /&gt;
In light of the recent [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 POODLE] findings, it&#039;s advisable to wherever possible turn off support for SSLv3.  This is quite simple, you can just append the following to your cipher list to explicitly disable SSLv3 support:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!SSLv3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10205</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=10205"/>
		<updated>2014-10-21T09:28:44Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Perfect Forward Secrecy (PFS) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probabky a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Ultimately when choosing SSl/TLS ciphers it is the usual chose of security or usabililty?  Increasing one usually decreases the other.  Nonetheles, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://raymii.org/s/tutorials/Pass_the_SSL_Labs_Test_on_Lighttpd_%28Mitigate_the_CRIME_and_BEAST_attack_-_Disable_SSLv2_-_Enable_PFS%29.html Source]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== POODLE attack (CVE-2014-3566) ===&lt;br /&gt;
&lt;br /&gt;
In light of the recent [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 POODLE] findings, it&#039;s advisable to wherever possible turn off support for SSLv3.  This is quite simple, you can just append the following to your cipher list to explicitly disable SSLv3 support:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
:!SSLv3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10089</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10089"/>
		<updated>2014-07-18T12:04:55Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: amended transparent proxy definition re: authentication&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server is not usually involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.  There are however, ways around this, which usually involve redirecting the client to a login page (or captive portal).&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation apears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames enabled&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=10088</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=10088"/>
		<updated>2014-07-18T11:46:55Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some crazy Drum &#039;n&#039; Bass:&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Doorway+Gridlock+Echo+Remix/aGkez?src=5 &#039;Doorway&#039; by Usual Suspects (Gridlock &amp;amp; Echo remix)]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/No+Test/3GHSp1?src=5 &#039;No test&#039; by Distorted Minds]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10081</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10081"/>
		<updated>2014-07-11T10:13:06Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Amend /etc/squid/squid.conf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server cannot be involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation apears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The decision you&#039;re making with the &#039;sslproxy_cert_error&#039; (and potentially the &#039;sslproxy_flags&#039;) option is to either close the connection when a certificate error is encountered (such as a self-signed, untrusted certificate is presented), or to pass certificate errors onto the client to allow them to make the choice about the site and whether or not to trust the certificate.&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames enabled&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raid_Administration&amp;diff=10080</id>
		<title>Raid Administration</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raid_Administration&amp;diff=10080"/>
		<updated>2014-07-08T11:29:02Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* General recommendations */  corrected minor error re: spare disks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Whilst there are articles on RAID installation (see [[ISCSI Raid and Clustered File Systems|1]], [[High performance SCST iSCSI Target on Linux software Raid|2]], [[Linux iSCSI Target (TCM)|3]], [[Setting up a software RAID1 array|4]], [[Setting up a /var partition on software IDE raid1|5]], [[Setting up disks manually|6]], [[Ensuring that /var is correctly mounted on HDD|7]]     for example) to various degrees, this article is designed to provide practical information on RAID administration, regardless of RAID type used or installation method.&lt;br /&gt;
&lt;br /&gt;
This article is of course using linux software RAID, also known as &#039;&#039;md&#039;&#039; after the controlling process, which is controlled by the &amp;lt;code&amp;gt;mdadm&amp;lt;/code&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
For the purposes of this example, we will create a [https://en.wikipedia.org/wiki/RAID#RAID_1 RAID 1] array across /dev/sda and /dev/sdb using the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script (more specifically the [[Alpine Setup Scripts#RAID|setup-disk script]]) and then add /dev/sdc to the array after installation.  This will add it as a hot spare which will be used if one of the other drives becomes degraded.  Alternatively the drive can immediately be added to the RAID array (as explained in the optional steps).&lt;br /&gt;
The instructions in this article should work regardless of whether you are using [https://en.wikipedia.org/wiki/RAID#RAID_1 RAID 1] or [https://en.wikipedia.org/wiki/RAID#RAID_5 RAID 5] and whether you have [[Setting up disks manually|setup your disks manually]] or with the [[Install to disk|setup script]], unless stated otherwise.&lt;br /&gt;
&lt;br /&gt;
In this example /dev/sda, /dev/sdb and /dev/sdc are all virtual 2GB disks on a VMware machine (it doesn&#039;t matter that it&#039;s a VM, the same process applies to a real machine with physical disks of larger sizes).&lt;br /&gt;
&lt;br /&gt;
In our example, all disks are available (present) at the time of installation, however /dev/sdc could be added at a later time; this has no impact on the procedure described other than having to physically add the disk.&lt;br /&gt;
&lt;br /&gt;
== Initial setup ==&lt;br /&gt;
&lt;br /&gt;
Install with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; and pass the relevant disks to [[Alpine setup scripts#setup-disk|setup-disk]] (in our case &amp;lt;code&amp;gt;sda sdb&amp;lt;/code&amp;gt;) and use installation method &amp;lt;code&amp;gt;sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This should create the following disk setup (it will differ in your setup since values of course depend on drive size):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md0 composed of /dev/sda1 and /dev/sdb1 ~100MB mounted as /boot&lt;br /&gt;
&lt;br /&gt;
md1 composed of /dev/sda2 and /dev/sdb2 ~512MB as /swap&lt;br /&gt;
&lt;br /&gt;
md2 composed of /dev/sda3 and /dev/sdb3 ~1400MB mounted as /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can see, we have redundancy across the two drives /dev/sda and /dev/sdb.&lt;br /&gt;
&lt;br /&gt;
== Review ==&lt;br /&gt;
&lt;br /&gt;
Run &amp;lt;code&amp;gt;df -h&amp;lt;/code&amp;gt; and observe that the RAID arrays are mounted, not the disk partitions as usual.&lt;br /&gt;
&lt;br /&gt;
To see information on the current RAID partitions use the query option:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --query /dev/md0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or for more information use the detail option&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --detail /dev/md1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After the initial setup, if you haven&#039;t added the third drive (/dev/sdc) now is the time to poweroff and physically add it to the machine.&lt;br /&gt;
&lt;br /&gt;
== Add devices to the array ==&lt;br /&gt;
&lt;br /&gt;
Now, let&#039;s add /dev/sdc to the RAID array.&lt;br /&gt;
&lt;br /&gt;
=== Copy partition table ===&lt;br /&gt;
&lt;br /&gt;
First, copy the partition table from an existing drive to the new drive.  Be &#039;&#039;&#039;very&#039;&#039;&#039; careful with the dd command and ensure you are copying from/to the correct place!  {{Note|for [[Setting up LVM on GPT-labeled disks|GPT]] partitioning, which you might have used if you&#039;ve setup your disks manually, this dd command is unlikely to work since [https://en.wikipedia.org/wiki/GUID_Partition_Table GPT] stores its information differently}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 dd if=/dev/sda of=/dev/sdc bs=512 count=1  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ensure this worked correctly by comparing the output of sfdisk, they should be identical:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 sfdisk --dump /dev/sda&lt;br /&gt;
 sfdisk --dump /dev/sdc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add devices ===&lt;br /&gt;
&lt;br /&gt;
Now add the partitions of the new disk to the relevant RAID arrays.  Be sure to add the correct partitions to the correct arrays!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm /dev/md0 -a /dev/sdc1&lt;br /&gt;
 mdadm /dev/md1 -a /dev/sdc2&lt;br /&gt;
 mdadm /dev/md2 -a /dev/sdc3&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see something like &amp;lt;code&amp;gt;mdadm: added /dev/sdc1&amp;lt;/code&amp;gt; if the command is successful.  The &#039;&#039;&#039;-a&#039;&#039;&#039; flag is for &#039;&#039;&#039;add&#039;&#039;&#039;.&lt;br /&gt;
 &lt;br /&gt;
Now see how the output of the query command has changed from earlier:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --query /dev/md0&lt;br /&gt;
 mdadm --query /dev/md1&lt;br /&gt;
 mdadm --query /dev/md2&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
You should see we still have two devices in each array, plus now we have a spare.  A spare is an inactive device that is a member of the array; it will only be used if one of the other devices fails.   If this is good enough for you, you&#039;re done!&lt;br /&gt;
&lt;br /&gt;
=== Grow the array (optional) ===&lt;br /&gt;
&lt;br /&gt;
Otherwise you can take the optional step to add the &#039;spare&#039; device so it immediately becomes part of the array.  Since we&#039;re using RAID 1 in our example this effectively gives us &#039;&#039;another&#039;&#039; backup of all data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --grow /dev/md0 -n 2&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Should give you something like &amp;lt;code&amp;gt;mdamd: /dev/md0: no change requested&amp;lt;/code&amp;gt;.  This is because we already have &amp;lt;code&amp;gt;-n 2&amp;lt;/code&amp;gt; set (so we use 2 devices in the array).  Obviously the &#039;&#039;&#039;--grow&#039;&#039;&#039; flag is used to &#039;&#039;&#039;grow&#039;&#039;&#039; the array and increase (or [[Raid_Administration#Change_device_count_.28optional.29|decrease]]) the number of devices in the array. Let&#039;s increase the value and bring in the additional device to the array:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --grow /dev/md0 -n 3 &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
You should see something like &amp;lt;code&amp;gt;raid_disks for /dev/md0 set to 3&amp;lt;/code&amp;gt; if successful.  &#039;&#039;&#039;-n 3&#039;&#039;&#039; specifies that there should be three &#039;&#039;active&#039;&#039; devices in the array.  There can still be additional &#039;&#039;spare&#039;&#039; devices if you add more and do not grow the array.&lt;br /&gt;
&lt;br /&gt;
Review the output of &amp;lt;code&amp;gt;mdadm --query /dev/md0&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;mdadm --detail /dev/md0&amp;lt;/code&amp;gt; again to confirm it worked.  Don&#039;t worry if you see something about &#039;spare rebuilding&#039; - this is normal and will be replaced with a state of &#039;active sync&#039; once data copying is complete.&lt;br /&gt;
&lt;br /&gt;
Ensure to add the other devices (partitions) to the arrays by increasing the device count for the other arrays (otherwise they will remain as spares and not be immediately utilised):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --grow /dev/md1 -n 3 &lt;br /&gt;
 mdadm --grow /dev/md2 -n 3 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Remove devices ==&lt;br /&gt;
&lt;br /&gt;
To remove a failed device use the following; remember you will need to remove all the partitions of the failing drive (devices) from the relevant RAID arrays.  In our example, we will mark the partitions of /dev/sdb as failed and remove them from the array:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm /dev/md0 -f /dev/sdb1 -r /dev/sdb1&lt;br /&gt;
 mdadm /dev/md1 -f /dev/sdb2 -r /dev/sdb2&lt;br /&gt;
 mdadm /dev/md2 -f /dev/sdb3 -r /dev/sdb3&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Check the output of &amp;lt;code&amp;gt;mdadm --detail /dev/md2&amp;lt;/code&amp;gt; and see how the device is marked as &#039;removed&#039;.&lt;br /&gt;
The &#039;&#039;&#039;-f&#039;&#039;&#039; flag is used to mark a device as &#039;&#039;&#039;failed&#039;&#039;&#039; and &#039;&#039;&#039;-r&#039;&#039;&#039; is used to &#039;&#039;&#039;remove&#039;&#039;&#039; a device from the array.&lt;br /&gt;
&lt;br /&gt;
To add a removed device back in, ensure it&#039;s partitioned correctly (replace the drive if necessary and copy over the partition table from a known good drive) and then simply add it back in again:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  mdadm /dev/md2 -a /dev/sdb3&lt;br /&gt;
&amp;lt;/pre&amp;gt;  &lt;br /&gt;
(repeat for other partitions as appropriate).  &lt;br /&gt;
   &lt;br /&gt;
=== Change device count (optional) ===&lt;br /&gt;
&lt;br /&gt;
To entirely remove the device from the array (assuming you are not going to add it back later for instance) amend the device count again, this will remove it from the list so it no longer shows as &#039;removed&#039; and we are back to two devices in the array: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 mdadm --grow /dev/md0 -n 2 &lt;br /&gt;
 mdadm --grow /dev/md1 -n 2 &lt;br /&gt;
 mdadm --grow /dev/md2 -n 2 &lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
If you do need to add disks back in again, you need to add them as spares (&amp;lt;code&amp;gt;mdadm /dev/md0 -a /dev/sdb1&amp;lt;/code&amp;gt; etc) and then change the device count if you wish to make the device active, as per the section on [[Raid_Administration#Add_devices_to_the_array|adding devices]].&lt;br /&gt;
&lt;br /&gt;
=== Zero the superblock ===&lt;br /&gt;
&lt;br /&gt;
Zeroing the superblock is important if you intend to take a disk from an array and add it to another array, for example on another machine.  Zeroing the superblock will prevent the RAID array from becoming confused about which array it should be building; leaving the old superblock information on a disk means it will try to read this old superblock information and this can cause all manner of headaches.  So, to remove the superblock from a disk so you can use it elsewhere, simply use the &amp;lt;code&amp;gt;--zero-superblock&amp;lt;/code&amp;gt; option.  To continue from our example above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mdadm --zero-superblock /dev/sdb1&lt;br /&gt;
mdadm --zero-superblock /dev/sdb2&lt;br /&gt;
mdadm --zero-superblock /dev/sdb3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
drive /dev/sdb can then be removed and added to another RAID array without causing issues.&lt;br /&gt;
&lt;br /&gt;
== General recommendations ==&lt;br /&gt;
&lt;br /&gt;
When making use of RAID arrays best practice is to have one more disk than is required and added as a spare.  This immediately provides some form of redundancy.  Remember that for RAID 1 you cannot go below 2 disks (well you can run on one disk, known as degraded mode, but &#039;&#039;this is best avoided at all costs&#039;&#039;) and with RAID 5 you cannot go below 3 disks. In short, if you are using RAID, have a &#039;&#039;spare&#039;&#039; device configured.  &lt;br /&gt;
&lt;br /&gt;
Disks cost money, but the data on those disks is often priceless!&lt;br /&gt;
&lt;br /&gt;
It&#039;s a good idea to have a test environment to play around with RAID &#039;&#039;before&#039;&#039; implementing it in a production environment.  Worst case, setup a [https://virtualbox.org/ VirtualBox] host and run an Alpine VM and play around with that, prior to using a production system.&lt;br /&gt;
&lt;br /&gt;
== Further information ==&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/mdadm man mdadm]&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/RAID RAID on wikipedia]&lt;br /&gt;
&lt;br /&gt;
[https://raid.wiki.kernel.org/index.php/Linux_Raid Linux RAID wiki at kernel.org]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=10079</id>
		<title>Alpine Package Keeper</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Package_Keeper&amp;diff=10079"/>
		<updated>2014-07-03T13:18:44Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Info on Packages */  -&amp;gt;added &amp;#039;listing installed packages&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--For searching: apk, APK--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because Alpine Linux is designed to run from RAM, package management involves two phases:&lt;br /&gt;
* Installing / Upgrading / Deleting packages on a running system&lt;br /&gt;
* Restoring a system to a previously configured state (e.g. after reboot), including all previously installed packages and locally modified configuration files. &#039;&#039;&#039;(RAM-Based Installs Only)&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;apk&#039;&#039;&#039; is the tool used to install, upgrade, or delete software on a running sytem.&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;lbu&#039;&#039;&#039; is the tool used to capture the data necessary to restore a system to a previously configured state.&lt;br /&gt;
&lt;br /&gt;
This page documents the [http://git.alpinelinux.org/cgit/apk-tools.git apk tool] - See the [[Alpine_local_backup|Alpine Local Backup page]] for the lbu tool.&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; tool has the following applets:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[#Add a Package|add]] &lt;br /&gt;
| Add new packages to the running system&lt;br /&gt;
|-&lt;br /&gt;
| [[#Remove a Package|del]]&lt;br /&gt;
| Delete packages from the running system&lt;br /&gt;
|-&lt;br /&gt;
| fix &lt;br /&gt;
| Attempt to repair or upgrade an installed package &lt;br /&gt;
|-&lt;br /&gt;
| [[#Update the Package list|update]] &lt;br /&gt;
| Update the index of available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Info on Packages|info]]&lt;br /&gt;
| Prints information about installed or available packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Search for Packages|search]] &lt;br /&gt;
| Search for packages or descriptions with wildcard patterns&lt;br /&gt;
|-&lt;br /&gt;
| [[#Upgrade a Running System|upgrade]]&lt;br /&gt;
| Upgrade the currently installed packages&lt;br /&gt;
|-&lt;br /&gt;
| [[#Cache Maintenance|cache]]&lt;br /&gt;
| Maintenance operations for locally cached package repository&lt;br /&gt;
|-&lt;br /&gt;
| version &lt;br /&gt;
| Compare version differences between installed and available packages&lt;br /&gt;
|-&lt;br /&gt;
| index &lt;br /&gt;
| create a repository index from a list of packages&lt;br /&gt;
|-&lt;br /&gt;
| fetch &lt;br /&gt;
| download (but not install) packages&lt;br /&gt;
|-&lt;br /&gt;
| audit &lt;br /&gt;
| List changes to the file system from pristine package install state&lt;br /&gt;
|-&lt;br /&gt;
| verify &lt;br /&gt;
| Verify a package signature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Packages and Repositories =&lt;br /&gt;
&lt;br /&gt;
Software packages for Alpine Linux are digitally signed tar.gz archives containing the programs, configuration files, and dependency metadata. They have the extension &amp;lt;code&amp;gt;.apk&amp;lt;/code&amp;gt;, and are often called &amp;quot;a-packs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The packages are stored in one or more &#039;&#039;repositories&#039;&#039;. A repository is simply a directory with a collection of *.apk files.  The directory must include a special index file, named {{Path|APKINDEX.tar.gz}} to be considered a repository.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;apk&#039;&#039;&#039; utility can install packages from multiple repositories.  The list of repositories to check is stored in {{Path|/etc/apk/repositories}}, one repository per line. If you booted from USB stick ({{Path|/media/sda1}}) or CD-ROM ({{Path|/media/cdrom}}), your repository file probably looks something like this:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|/media/sda1/apks/}}&lt;br /&gt;
&lt;br /&gt;
In addition to local repositories, the &#039;&#039;&#039;apk&#039;&#039;&#039; utility uses &#039;&#039;&#039;busybox wget&#039;&#039;&#039; to fetch packages using &#039;&#039;http:&#039;&#039;, &#039;&#039;https:&#039;&#039; or &#039;&#039;ftp:&#039;&#039; protocols. The following is a valid repository file:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
/media/sda1/apks&lt;br /&gt;
http://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
https://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
ftp://dl-3.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Currently there are no public https or ftp repositories. The protocols are available for local repositories.}}&lt;br /&gt;
&lt;br /&gt;
== Repository pinning ==&lt;br /&gt;
&lt;br /&gt;
You can specify additional &amp;quot;tagged&amp;quot; repositories in {{Path|/etc/apk/repositories}}:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/apk/repositories|&lt;br /&gt;
http://nl.alpinelinux.org/alpine/v2.6/main&lt;br /&gt;
@edge http://nl.alpinelinux.org/alpine/edge/main&lt;br /&gt;
@testing http://nl.alpinelinux.org/alpine/edge/testing&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After which you can &amp;quot;pin&amp;quot; dependencies to these tags using:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add stableapp newapp@edge bleedingapp@testing}}&lt;br /&gt;
&lt;br /&gt;
Apk will now by default only use the untagged repositories, but adding a tag to specific package:&lt;br /&gt;
&lt;br /&gt;
1. will prefer the repository with that tag for the named package, even if a later version of the package is available in another repository&lt;br /&gt;
&lt;br /&gt;
2. &#039;&#039;allows&#039;&#039; pulling in dependencies for the tagged package from the tagged repository (though it &#039;&#039;prefers&#039;&#039; to use untagged repositories to satisfy dependencies if possible)&lt;br /&gt;
&lt;br /&gt;
= Update the Package list =&lt;br /&gt;
&lt;br /&gt;
Remote repositories change as packages are added and upgraded.   To get the latest list of  available packages, use the &#039;&#039;update&#039;&#039; command.  The command downloads the {{Path|APKINDEX.tar.gz}} from each repository and stores it in the local cache, typically {{Path|/var/lib/apk/}} or {{Path|/etc/apk/cache/}}.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk update}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
fetch http://dl-3.alpinelinux.org/alpine/v2.1/main/APKINDEX.tar.gz&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|If using remote repositories, it is a good idea to do an &#039;&#039;&#039;update&#039;&#039;&#039; just before doing an &#039;&#039;&#039;add&#039;&#039;&#039; or &#039;&#039;&#039;upgrade&#039;&#039;&#039; command.  That way you know you are using the latest software available.}}&lt;br /&gt;
&lt;br /&gt;
= Add a Package =&lt;br /&gt;
&lt;br /&gt;
Use &#039;&#039;&#039;add&#039;&#039;&#039; to install packages from a repository.  Any necessary dependencies are also installed.  If you have multiple repositories, the &#039;&#039;&#039;add&#039;&#039;&#039; command installs the newest package.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssh&lt;br /&gt;
apk add openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories. To install a package from the edge/testing repository without changing your repository configuration file, use the command below. This will tell apk to use that particular repository.&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add cherokee --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Be careful when using third-party or the testing repository. Your system can go down.}}&lt;br /&gt;
&lt;br /&gt;
= Remove a Package  =&lt;br /&gt;
Use &#039;&#039;&#039;del&#039;&#039;&#039; to remove a package (and dependencies that are no longer needed.)  &lt;br /&gt;
&lt;br /&gt;
{{cmd|apk del openssh&lt;br /&gt;
apk del openssh openntp vim}}&lt;br /&gt;
&lt;br /&gt;
= Upgrade a Running System =&lt;br /&gt;
&lt;br /&gt;
To upgrade &#039;&#039;all&#039;&#039; the packages of a running system, use &#039;&#039;&#039;upgrade&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To upgrade &#039;&#039;only a few&#039;&#039; packages, use the &#039;&#039;&#039;add&#039;&#039;&#039; command with the &#039;&#039;-u&#039;&#039; or &#039;&#039;--upgrade&#039;&#039; option:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk add --upgrade busybox &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Remember that when you reboot your machine, the remote repository will not be available until after networking is started.   This means packages newer than your local boot media will likely not be installed after a reboot. To make an &amp;quot;upgrade&amp;quot; persist over a reboot, use a [[#Local Cache|local cache]].}}&lt;br /&gt;
&lt;br /&gt;
= Search for Packages =&lt;br /&gt;
The &#039;&#039;&#039;search&#039;&#039;&#039; command searches the repository Index files for installable packages. &lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
* To list all packages available, along with their descriptions: {{cmd|apk search -v}}&lt;br /&gt;
* To list all packages are part of the ACF system: {{cmd|apk search -v &#039;acf*&#039; }}&lt;br /&gt;
* To list all packages that list NTP as part of their description, use the &#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039; option: {{cmd|apk search -v --description &#039;NTP&#039; }}&lt;br /&gt;
&lt;br /&gt;
= Info on Packages =&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;info&#039;&#039;&#039; command provides information on the contents of packages, their dependencies, and which files belong to a package.&lt;br /&gt;
&lt;br /&gt;
For a given package, each element can be chosen (for example, &#039;&#039;-w&#039;&#039; to show just the webpage information); or all information is displayed with the &#039;&#039;-a&#039;&#039; command.&lt;br /&gt;
&lt;br /&gt;
Example: {{cmd|apk info -a zlib}}&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 description:&#039;&#039;&#039;&lt;br /&gt;
 A compression/decompression Library&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 webpage:&#039;&#039;&#039;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://zlib.net&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 installed size:&#039;&#039;&#039;&lt;br /&gt;
 94208&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 depends on:&#039;&#039;&#039;&lt;br /&gt;
 libc0.9.32&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 is required by:&#039;&#039;&#039;&lt;br /&gt;
 libcrypto1.0-1.0.0-r0&lt;br /&gt;
 apk-tools-2.0.2-r4&lt;br /&gt;
 openssh-client-5.4_p1-r2&lt;br /&gt;
 openssh-5.4_p1-r2&lt;br /&gt;
 libssl1.0-1.0.0-r0&lt;br /&gt;
 freeswitch-1.0.6-r6&lt;br /&gt;
 atop-1.25-r0 &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 contains:&#039;&#039;&#039;&lt;br /&gt;
 lib/libz.so.1.2.5&lt;br /&gt;
 lib/libz.so.1&lt;br /&gt;
 lib/libz.so &lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;zlib-1.2.5-r1 triggers:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
As shown in the example you can determine&lt;br /&gt;
* The &#039;&#039;&#039;description&#039;&#039;&#039; of the package (&#039;&#039;-d&#039;&#039; or &#039;&#039;--description&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;webpage&#039;&#039;&#039; where the application is hosted (&#039;&#039;-w&#039;&#039; or &#039;&#039;--webpage&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;size&#039;&#039;&#039; the package will require once installed (in bytes) (&#039;&#039;-s&#039;&#039; or &#039;&#039;--size&#039;&#039;)&lt;br /&gt;
* What packages are required to use this one  (&#039;&#039;&#039;depends&#039;&#039;&#039;) (&#039;&#039;-R&#039;&#039; or &#039;&#039;--depends&#039;&#039;)&lt;br /&gt;
* What packages require this one to be installed (&#039;&#039;&#039;required by&#039;&#039;&#039;) (&#039;&#039;-r&#039;&#039; or &#039;&#039;--rdepends&#039;&#039;)&lt;br /&gt;
* The &#039;&#039;&#039;contents&#039;&#039;&#039; of the package, that is, which files it installs (&#039;&#039;-L&#039;&#039; or &#039;&#039;--contents&#039;&#039;)&lt;br /&gt;
* Any &#039;&#039;&#039;triggers&#039;&#039;&#039; this package sets. (&#039;&#039;-t&#039;&#039; or &#039;&#039;--triggers&#039;&#039;) Listed here are directories that are watched; if a change happens to the directory, then the trigger script is run at the end of the apk add/delete.   For example, doing a depmod once after installing all packages that add kernel modules.&lt;br /&gt;
&lt;br /&gt;
{{Tip|The &#039;&#039;&#039;info&#039;&#039;&#039; command is also useful to determine which package a file belongs to.  For example: {{cmd|apk info --who-owns /sbin/lbu}} will display&lt;br /&gt;
&lt;br /&gt;
 /sbin/lbu is owned by alpine-conf-x.x-rx&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Listing installed packages ==&lt;br /&gt;
&lt;br /&gt;
To list all installed packages, use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apk info&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all installed packages in alphabetical order, with a description of each, do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;apk -vv info|sort&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Additional apk Commands =&lt;br /&gt;
In progress...&lt;br /&gt;
&lt;br /&gt;
= Local Cache =&lt;br /&gt;
&lt;br /&gt;
{{:Local_APK_cache}}&lt;br /&gt;
&lt;br /&gt;
= Advanced APK Usage =&lt;br /&gt;
&lt;br /&gt;
== Holding a specific package back ==&lt;br /&gt;
&lt;br /&gt;
In certain cases, you may want to upgrade a system, but keep a specific package at a back level.  It is possible to add &amp;quot;sticky&amp;quot; or versioned dependencies.  For instance, to hold the &#039;&#039;asterisk&#039;&#039; package to the 1.6.2 level or lower:&lt;br /&gt;
{{cmd|1=apk add asterisk=1.6.0.21-r0}}&lt;br /&gt;
or&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;lt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
after which a {{cmd|apk upgrade}}&lt;br /&gt;
&lt;br /&gt;
will upgrade the entire system, keeping the asterisk package at the 1.6.0 or lower level&lt;br /&gt;
&lt;br /&gt;
To later upgrade to the current version,&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add &#039;asterisk&amp;gt;1.6.1&#039;}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Package Manager]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Entropy_and_randomness&amp;diff=10078</id>
		<title>Entropy and randomness</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Entropy_and_randomness&amp;diff=10078"/>
		<updated>2014-07-02T18:09:05Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: removed reference to wipe&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Entropy_%28computing%29 Entropy] is described as &#039;a numerical measure of the uncertainty of an outcome&#039; and is often associated with chaos or disorder however is often more simply called [https://en.wikipedia.org/wiki/Randomness randomness].&lt;br /&gt;
&lt;br /&gt;
It is important for a secure operating system to have sufficient quantities of entropy available for various crypotographic and non-cryptographic purposes, such as:&lt;br /&gt;
&lt;br /&gt;
* Generation of cryptographic keys&lt;br /&gt;
&lt;br /&gt;
* Address Space Layout Randomisation ([http://en.wikipedia.org/wiki/PaX#Address_space_layout_randomization ASLR]) - used by default in Alpine of course ;)&lt;br /&gt;
&lt;br /&gt;
* TCP port randomisation ([https://en.wikipedia.org/wiki/Network_address_translation NAT], outbound connection)&lt;br /&gt;
&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Reliable_transmission TCP sequence number] selection (see [https://en.wikipedia.org/wiki/TCP_sequence_prediction_attack this too)]&lt;br /&gt;
&lt;br /&gt;
* Writing random files for testing network functionality and throughput&lt;br /&gt;
&lt;br /&gt;
* Overwriting hard disks prior to reuse or resale or encryption&lt;br /&gt;
&lt;br /&gt;
Entropy is contained within a &#039;&#039;&#039;pool&#039;&#039;&#039;, which draws its entropy from various &#039;&#039;&#039;sources&#039;&#039;&#039;. To view the current amount of entropy in the pool:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|more /proc/sys/kernel/random/entropy_avail}}&lt;br /&gt;
&lt;br /&gt;
To view the maximum limit of entropy that the pool can hold:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|more /proc/sys/kernel/random/poolsize}}&lt;br /&gt;
&lt;br /&gt;
On a standard system the limit is 4096 bits (512 bytes).  The [https://grsecurity.net/ gr-sec] patch used on Alpine increases this limit to 16384 bits (2048 bytes).&lt;br /&gt;
Entropy is added to the pool in bits from various sources, &amp;quot;the relative number of unknown bits per event is roughly 8/keyboard, 12/mouse, 3/disk, 4/interrupt&amp;quot; [http://www.issihosts.com/haveged/history.html#intro source] meaning that on a headless server (without mouse and keyboard attached), which ironically is often a system requiring the most entropy, entropy generation is somewhat limited.&lt;br /&gt;
&lt;br /&gt;
The entropy from the pool can be accessed in two ways by default:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/random&#039;&#039;&#039; - This is a [https://en.wikipedia.org/wiki/Blocking_%28computing%29 blocking] resource, so it will use available entropy from the pool.  If more entropy is required than is available, the process will wait until more entropy is available in the pool.  Due to this behaviour, /dev/random is best used where small amounts of high quality randomness are required, such as for cryptographic keys.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/dev/urandom&#039;&#039;&#039; - Is a non-blocking resource. It uses a seed value from the same entropy pool as /dev/random and therefore, if little entropy is available in the pool, it is recommended not to use /dev/urandom until more entropy is made available in the pool.  It runs the seed value through an algorithm and so is a [http://en.wikipedia.org/wiki/Pseudo-random_number_generator pseudo-random number generator], operating much faster than /dev/random.  /dev/urandom is best used for non-cryptographic purposes such as overwriting disks.&lt;br /&gt;
&lt;br /&gt;
Writing to /dev/random or /dev/urandom will update the entropy pool with the data written, but this will not result in a higher entropy count.  This means that it will impact the contents read from both files, but it will not make reads from /dev/random faster.&lt;br /&gt;
For more information see the [http://www.manpagez.com/man/4/random/ random manpage]&lt;br /&gt;
&lt;br /&gt;
It is generally recommended wherever entropy is used heavily to supply additional entropy sources; some possibilities are below.  Adding more sources of entropy to feed into the pool is a good idea.  It makes an attackers job more difficult, because there will be more sources they have to gain control over (or at the very least observe at source), and adding more sources of entropy, even weak ones, can only result in higher entropy.&lt;br /&gt;
&lt;br /&gt;
If you are desperate for more entropy and are working on a headless server with no internet connection, you could try generating some via disk activity.  Just don&#039;t expect any miracles!  Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dd if=/dev/zero of=/var/tmp/tempfile bs=1M count=200 &amp;amp;&amp;amp; find / -size +1k &amp;amp;&amp;amp; ls -R / &amp;amp;&amp;amp; rm /var/tmp/tempfile &amp;amp;&amp;amp; sync&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your server is a &#039;run-from-ram&#039; setup and so you have no disks to create churn but require more entropy, it is strongly recommended to add alternative entropy sources as discussed below.&lt;br /&gt;
&lt;br /&gt;
== Alternative/Additional entropy sources ==&lt;br /&gt;
&lt;br /&gt;
=== Haveged ===&lt;br /&gt;
&lt;br /&gt;
[http://www.issihosts.com/haveged/ Haveged] generates entropy based on [http://www.issihosts.com/haveged/flutter.html CPU flutter].  The entropy is buffered and fed into the entropy pool when write_wakeup_threshold is reached.  Write a value (the number of bits) to it if you wish to change it: &lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo &amp;quot;1024&amp;quot; &amp;gt; /proc/sys/kernel/random/write_wakeup_threshold}}&lt;br /&gt;
&lt;br /&gt;
Or change it via haveged:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|haveged -w 1024}}&lt;br /&gt;
&lt;br /&gt;
Install [http://alpinelinux.org/apk/main/x86_64/haveged haveged], then start and set to autostart at boot:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk -U add haveged &amp;amp;&amp;amp; rc-service haveged start &amp;amp;&amp;amp; rc-update add haveged}}&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/haveged Further configuration] is possible however the defaults should work fine out of the box. &lt;br /&gt;
&lt;br /&gt;
=== Other possibilities ===&lt;br /&gt;
&lt;br /&gt;
Some other possibilites for entropy generation are:&lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/te/ timer entropy daemon] -  should provide on-demand entropy based on variances in timings of sleep command.&lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/ved/ video entropy daemon] - requires a video4linux-device, gathers entropy by taking a couple of images and calculating the differences and then the entropy of that.  Can be run on demand or as a cron job. &lt;br /&gt;
&lt;br /&gt;
*[http://www.vanheusden.com/aed/ audio entropy daemon] - requires alsa development libraries and an audio device.  Generates entropy by reading from audio device and de-baising data.&lt;br /&gt;
&lt;br /&gt;
*[http://vladz.devzero.fr/guchaos.php GUChaos] - &amp;quot;Give Us Chaos&amp;quot; provides on-demand entropy, by retrieving random blocks of bytes from the [http://www.random.org/ Random.org] website, and transforms them with a [http://en.wikipedia.org/wiki/Substitution_cipher polynumeric substitution cipher] before adding them to /dev/random until the entropy pool is filled.&lt;br /&gt;
&lt;br /&gt;
and hardware entropy generators such as: &lt;br /&gt;
&lt;br /&gt;
*[http://www.entropykey.co.uk/ Entropy Key] - USB hardware entropy generator&lt;br /&gt;
&lt;br /&gt;
It is also possible to replace /dev/random with [http://egd.sourceforge.net/ EGD, the Entropy Gathering Daemon], or to use this on systems that are not able to support /dev/random.  However, this is not required (or recommended) under normal circumstances.&lt;br /&gt;
&lt;br /&gt;
== Testing entropy with ENT ==&lt;br /&gt;
&lt;br /&gt;
It is possible to [http://en.wikipedia.org/wiki/Randomness_test test] entropy to see how statistically random it is.  Generally, such tests only reveal part of the picture, since some numbers can pass statistical entropy tests whilst they are not actually random.  Failing a statistical randomness test is not a good indicator of course!&lt;br /&gt;
&lt;br /&gt;
Make a folder for testing, and get hold of [http://www.fourmilab.ch/random/ ENT]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /tmp/test/make&lt;br /&gt;
cd /tmp/test/make&lt;br /&gt;
wget http://www.fourmilab.ch/random/random.zip&lt;br /&gt;
unzip random.zip&lt;br /&gt;
make&lt;br /&gt;
mv ./ent /tmp/test/&lt;br /&gt;
cd /tmp/test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create some random data.  In this example we read from /dev/urandom:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;dd if=/dev/urandom of=/tmp/test/urandomfile bs=1 count=16384&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the ENT test against it:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./ent /tmp/test/urandomfile}}&lt;br /&gt;
&lt;br /&gt;
Try the same test whilst treating the data as a stream of bits and printing an account of character occurrences:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|./ent -b -c /tmp/test/urandomfile}} &lt;br /&gt;
&lt;br /&gt;
Note any differences against the previous test. &lt;br /&gt;
 &lt;br /&gt;
I propose also generating larger streams of data (10&#039;s or 100&#039;s of MB) and testing against this too.  Any repeating data or patterns (caused by a small/poor seed value for instance) will make spotting any weaknesses and a lack of randomness much easier across large amounts of data than across small amounts.&lt;br /&gt;
&lt;br /&gt;
I also suggest running the test against known non-random files, so you may see that some tests show that such a file can have some characteristics of a random file, whilst completely failing other randomness tests.&lt;br /&gt;
&lt;br /&gt;
Finally, once you are done testing with ENT, it&#039;s good practice to delete the working folder:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|rm -r /tmp/test/}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other tests ===&lt;br /&gt;
&lt;br /&gt;
Other tests include [http://www.stat.fsu.edu/pub/diehard/ diehard] and [http://www.phy.duke.edu/~rgb/General/dieharder.php dieharder]&lt;br /&gt;
&lt;br /&gt;
== Further reading ==&lt;br /&gt;
&lt;br /&gt;
[http://rsmith.home.xs4all.nl/howto/fun-with-encryption-and-randomness.html visualising randomness]&lt;br /&gt;
&lt;br /&gt;
[http://www.linuxfromscratch.org/hints/downloads/files/entropy.txt linux from scratch]&lt;br /&gt;
&lt;br /&gt;
[http://blog.cloudflare.com/ensuring-randomness-with-linuxs-random-number-generator Cloudflare]&lt;br /&gt;
&lt;br /&gt;
[https://tools.ietf.org/html/rfc4086 RFC 4086 - Randomness Requirements for Security]&lt;br /&gt;
&lt;br /&gt;
[https://calomel.org/entropy_random_number_generators.html calomel.org]&lt;br /&gt;
&lt;br /&gt;
[http://www.av8n.com/turbid/paper/turbid.htm Turbid]&lt;br /&gt;
&lt;br /&gt;
[http://blog.cryptographyengineering.com/2012/02/random-number-generation-illustrated.html Random number generation: An illustrated primer]&lt;br /&gt;
&lt;br /&gt;
[https://factorable.net/weakkeys12.extended.pdf Mining Your Ps and Qs: Detection of Widespread Weak Keys in Network Devices, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://www.pinkas.net/PAPERS/gpr06.pdf  Analysis of the Linux Random Number Generator, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://cryptome.org/2014/03/eat-entropy-have-it.pdf How to Eat Your Entropy and Have it Too — Optimal Recovery Strategies for Compromised RNGs, PDF]&lt;br /&gt;
&lt;br /&gt;
[http://eprint.iacr.org/2013/338.pdf Security Analysis of Pseudo-Random Number Generators with Input: /dev/random is not Robust, PDF]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_configuration_management_scripts&amp;diff=10004</id>
		<title>Alpine configuration management scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_configuration_management_scripts&amp;diff=10004"/>
		<updated>2014-06-09T15:07:36Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: added busybox to setup-ntpd&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page summarizes the low-level behavior of the {{Path|/sbin/setup-*}} scripts on the Alpine ISO (and in a normal Alpine install).&lt;br /&gt;
&lt;br /&gt;
== setup-alpine ==&lt;br /&gt;
&lt;br /&gt;
For a higher-level walkthrough (using the &amp;quot;sys&amp;quot; installmode), see [[Install to disk|Basic HDD install]].&lt;br /&gt;
&lt;br /&gt;
This script accepts the following command-line switches (you can run &amp;lt;code&amp;gt;setup-alpine -h&amp;lt;/code&amp;gt; to see a usage message).&lt;br /&gt;
&lt;br /&gt;
{{Define|-a|Create an overlay file: this creates a temporary directory and saves its location in ROOT; however, the script doesn&#039;t export this variable so I think this feature isn&#039;t currently functional.}}&lt;br /&gt;
;-c &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&lt;br /&gt;
:Create a new &amp;quot;answerfile&amp;quot;, with default choices. You can edit the file and then invoke &amp;lt;code&amp;gt;setup-alpine -f &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
;-f &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&lt;br /&gt;
:Use an existing &amp;quot;answerfile&amp;quot;, which may override some or all of the interactive prompts.&lt;br /&gt;
{{Define|-q|Run in &amp;quot;quick mode.&amp;quot; See below for details.}}&lt;br /&gt;
&lt;br /&gt;
The script&#039;s behavior is to do the following, in order. Bracketed options represent extra configuration choices that can be supplied when running the auxiliary setup scripts manually, or by supplying an &amp;quot;answerfile&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;setup-keymap&amp;lt;/code&amp;gt; [us us]&lt;br /&gt;
# [[#setup-hostname|setup-hostname]] [-n alpine-test]&lt;br /&gt;
# [[#setup-interfaces|setup-interfaces]] [-i &amp;lt; interfaces-file]&lt;br /&gt;
# &amp;lt;code&amp;gt;/etc/init.d/networking --quiet start &amp;amp;&amp;lt;/code&amp;gt;&lt;br /&gt;
# if none of the networking interfaces were configured using dhcp, then: [[#setup-dns|setup-dns]] [-d example.com -n &amp;quot;8.8.8.8 [...]&amp;quot;]&lt;br /&gt;
# set the root password&lt;br /&gt;
# if not in quick mode, then: [[#setup-timezone|setup-timezone]] [-z UTC | -z America/New_York | -p EST+5]&lt;br /&gt;
# enable the new hostname (&amp;lt;code&amp;gt;/etc/init.d/hostname --quiet restart&amp;lt;/code&amp;gt;)&lt;br /&gt;
# add &amp;lt;code&amp;gt;networking&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;urandom&amp;lt;/code&amp;gt; to the &#039;&#039;&#039;boot&#039;&#039;&#039; rc level, and &amp;lt;code&amp;gt;acpid&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cron&amp;lt;/code&amp;gt; to the &#039;&#039;&#039;default&#039;&#039;&#039; rc level, and start the &#039;&#039;&#039;boot&#039;&#039;&#039; and &#039;&#039;&#039;default&#039;&#039;&#039; rc services&lt;br /&gt;
# extract the fully-qualified domain name and hostname from {{Path|/etc/resolv.conf}} and &amp;lt;code&amp;gt;hostname&amp;lt;/code&amp;gt;, and update {{Path|/etc/hosts}}&lt;br /&gt;
# [[#setup-proxy|setup-proxy]] [-q &amp;lt;nowiki&amp;gt;&amp;quot;http://webproxy:8080&amp;quot;&amp;lt;/nowiki&amp;gt;], and activate proxy if it was configured&lt;br /&gt;
# &amp;lt;code&amp;gt;setup-apkrepos&amp;lt;/code&amp;gt; [-r (to select a mirror randomly)]&lt;br /&gt;
# if not in quick mode, then: [[#setup-sshd|setup-sshd]] [-c openssh | dropbear | none]&lt;br /&gt;
# if not in quick mode, then: &amp;lt;code&amp;gt;setup-ntp&amp;lt;/code&amp;gt; [-c chrony | openntpd | busybox | none]&lt;br /&gt;
# if not in quick mode, then: &amp;lt;code&amp;gt;DEFAULT_DISK=none&amp;lt;/code&amp;gt; [[#setup-disk|setup-disk]] &amp;lt;code&amp;gt;-q&amp;lt;/code&amp;gt; [-m data /dev/sda]&lt;br /&gt;
# if installation mode selected during setup-disk was &amp;quot;data&amp;quot; instead of &amp;quot;sys&amp;quot;, then: &amp;lt;code&amp;gt;setup-lbu&amp;lt;/code&amp;gt; [/media/sdb1]&lt;br /&gt;
# if installation mode selected during setup-disk was &amp;quot;data&amp;quot; instead of &amp;quot;sys&amp;quot;, then: &amp;lt;code&amp;gt;setup-apkcache&amp;lt;/code&amp;gt; [/media/sdb1/cache | none]&lt;br /&gt;
&lt;br /&gt;
== setup-hostname ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-hostname&amp;lt;/code&amp;gt; [-h] [-n hostname]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-n&#039;&#039;&#039; &amp;lt;var&amp;gt;Specify hostname&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This script allows quick and easy setup of the system hostname by writing it to {{Path|/etc/hostname}}.  The script prevents you from writing an invalid hostname (such as one that used invalid characters or starts with a &#039;-&#039; or is too long).&lt;br /&gt;
The script can be invoked manually or is called as part of the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
== setup-interfaces ==&lt;br /&gt;
{{Cmd|setup-interfaces [-i &amp;amp;lt; &amp;lt;var&amp;gt;interfaces-file&amp;lt;/var&amp;gt;]}}&lt;br /&gt;
&lt;br /&gt;
Note that the contents of &amp;lt;var&amp;gt;interfaces-file&amp;lt;/var&amp;gt; has to be supplied as stdin, rather than naming the file as an additional argument. The contents should have the format of {{Path|/etc/network/interfaces}}, such as:&lt;br /&gt;
&lt;br /&gt;
 auto lo&lt;br /&gt;
 iface lo inet loopback&lt;br /&gt;
 &lt;br /&gt;
 auto eth0&lt;br /&gt;
 iface eth0 inet dhcp&lt;br /&gt;
     hostname alpine-test&lt;br /&gt;
&lt;br /&gt;
== setup-dns ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-dns&amp;lt;/code&amp;gt; [-h] [-d domain name] [-n name server]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-d&#039;&#039;&#039; &amp;lt;var&amp;gt;specify search domain name&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-n&#039;&#039;&#039; &amp;lt;var&amp;gt;name server IP&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The setup-dns script is stored in {{Path|/sbin/setup-dns}} and allows quick and simple setup of DNS servers (and a DNS search domain if required).  Simply running &amp;lt;code&amp;gt;setup-dns&amp;lt;/code&amp;gt; will allow interactive use of the script, or the options can be specified.&lt;br /&gt;
&lt;br /&gt;
The information fed to this script is written to {{Path|/etc/resolv.conf}}&lt;br /&gt;
&lt;br /&gt;
Example usage: {{Cmd|setup-dns -d example.org -n 8.8.8.8}}&lt;br /&gt;
&lt;br /&gt;
Example {{Path|/etc/resolv.conf}}:&lt;br /&gt;
&lt;br /&gt;
 search example.org&lt;br /&gt;
 nameserver 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
It can be run manually but is also invoked in the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script unless interfaces are configured for DHCP.&lt;br /&gt;
&lt;br /&gt;
== setup-timezone ==&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-timezone&amp;lt;/code&amp;gt; [-z UTC | -z America/New_York | -p EST+5]&lt;br /&gt;
&lt;br /&gt;
Can pre-select the timezone using either of these switches:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-z&#039;&#039;&#039; &amp;lt;var&amp;gt;subfolder of&amp;lt;/var&amp;gt; {{Path|/usr/share/zoneinfo}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-p&#039;&#039;&#039; &amp;lt;var&amp;gt;POSIX TZ format&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-proxy ==&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-proxy&amp;lt;/code&amp;gt; [-hq] [PROXYURL]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-q&#039;&#039;&#039; &amp;lt;var&amp;gt;Quiet mode&amp;lt;/var&amp;gt; prevents changes from taking effect until after reboot&lt;br /&gt;
&lt;br /&gt;
This script requests the system proxy to use in the form &amp;lt;code&amp;gt;http://&amp;lt;proxyurl&amp;gt;:&amp;lt;port&amp;gt;&amp;lt;/code&amp;gt; for example:&lt;br /&gt;
&amp;lt;code&amp;gt;http://10.0.0.1:8080&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set no system proxy use &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt;.&lt;br /&gt;
This script exports the following environmental variables: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;http_proxy=$proxyurl&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;https_proxy=$proxyurl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ftp_proxy=$proxyurl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;$proxyurl&amp;lt;/code&amp;gt; is the value input.  &lt;br /&gt;
If &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt; was chosen then the value it is set to a blank value (and so no proxy is used).&lt;br /&gt;
&lt;br /&gt;
== setup-sshd ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-sshd&amp;lt;/code&amp;gt; [-h] [-c choice of SSH daemon]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-c&#039;&#039;&#039; &amp;lt;var&amp;gt;SSH daemon&amp;lt;/var&amp;gt; where SSH daemon can be one of the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;openssh&amp;lt;/code&amp;gt; install the {{Pkg|openSSH}} daemon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;dropbear&amp;lt;/code&amp;gt; install the {{Pkg|dropbear}} daemon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt; Do not install an SSH daemon&lt;br /&gt;
&lt;br /&gt;
Example usage: {{Cmd|setup-sshd -c dropbear}}&lt;br /&gt;
&lt;br /&gt;
The setup-sshd script is stored in {{Path|/sbin/setup-sshd}} and allows quick and simple setup of either the OpenSSH or Dropbear SSH daemon &amp;amp; client. &lt;br /&gt;
It can be run manually but is also invoked in the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
== setup-disk ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;DEFAULT_DISK=none setup-disk -q&amp;lt;/code&amp;gt; [-m data | sys] [&amp;lt;var&amp;gt;mountpoint directory&amp;lt;/var&amp;gt; | /dev/sda ...]&lt;br /&gt;
&lt;br /&gt;
This script accepts the following command-line switches:&lt;br /&gt;
&lt;br /&gt;
;-k &amp;lt;var&amp;gt;kernel flavor&amp;lt;/var&amp;gt;&lt;br /&gt;
;-o &amp;lt;var&amp;gt;apkovl file&amp;lt;/var&amp;gt;&lt;br /&gt;
:Restore system from &amp;lt;var&amp;gt;apkovl file&amp;lt;/var&amp;gt;&lt;br /&gt;
;-m data | sys&lt;br /&gt;
:Don&#039;t prompt for installation mode. With &#039;&#039;&#039;-m data&#039;&#039;&#039;, the supplied devices are formatted to use as a {{Path|/var}} volume.&lt;br /&gt;
{{Define|-r|Use RAID1 with a single disk (degraded mode)}}&lt;br /&gt;
{{Define|-L|Create and use volumes in a LVM group}}&lt;br /&gt;
;-s &amp;lt;var&amp;gt;swap size in MB&amp;lt;/var&amp;gt;&lt;br /&gt;
:Use 0 to disable swap&lt;br /&gt;
{{Define|-q|Exit quietly if no disks are found}}&lt;br /&gt;
{{Define|-v|Verbose mode}}&lt;br /&gt;
&lt;br /&gt;
The script also honors the following environment variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BOOT_SIZE&amp;lt;/code&amp;gt;&lt;br /&gt;
:Size of the boot partition in MB; defaults to 100. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SWAP_SIZE&amp;lt;/code&amp;gt;&lt;br /&gt;
:Size of the swap volume in MB; set to 0 to disable swap. If not specified, will default to twice RAM, up to 4096, but won&#039;t be more than 1/3 the size of the smallest disk, and if less than 64 will just be 0. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ROOTFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the / volume; defaults to ext4. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BOOTFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the /boot volume; defaults to ext4. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;VARFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the /var volume; defaults to ext4. Only used if &#039;&#039;&#039;-m data&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SYSROOT&amp;lt;/code&amp;gt;&lt;br /&gt;
:Mountpoint to use when creating volumes and doing traditional disk install (&#039;&#039;&#039;-m data&#039;&#039;&#039;). Defaults to {{Path|/mnt}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MBR&amp;lt;/code&amp;gt;&lt;br /&gt;
:Path of MBR binary code, defaults to {{Path|/usr/share/syslinux/mbr.bin}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Writes to /tmp/ovlfiles, /tmp/alpine-install-diskmode.out, and /tmp/sfdisk.out but that never seems to be used elsewhere. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Partitioning ===&lt;br /&gt;
&lt;br /&gt;
If you have complex partitioning needs, you can partition, format, and mount your volumes manually, then just supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;. Doing so implicitly behaves as though &#039;&#039;&#039;-m sys&#039;&#039;&#039; had also been specified.&lt;br /&gt;
&lt;br /&gt;
See [[Setting up disks manually]] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== RAID ====&lt;br /&gt;
&amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; will automatically build a RAID array if you supply the &#039;&#039;&#039;-r&#039;&#039;&#039; switch, or if you specify more than one device. The array will always be [https://en.m.wikipedia.org/wiki/Standard_RAID_levels#RAID_1 RAID1] (and [https://raid.wiki.kernel.org/index.php/RAID_superblock_formats#The_version-0.90_Superblock_Format --metadata=0.90]) for the /boot volumes, but will be [https://en.m.wikipedia.org/wiki/Standard_RAID_levels#RAID_5 RAID5] (and [https://raid.wiki.kernel.org/index.php/RAID_superblock_formats#The_version-1_Superblock_Format --metadata=1.2] for non-boot volumes when 3 or more devices are supplied.&lt;br /&gt;
&lt;br /&gt;
If you instead want to build your RAID array manually, see [[Setting up a software RAID1 array]]. Then format and mount the disks, and supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== LVM ====&lt;br /&gt;
&amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; will automatically build and use volumes in a LVM group if you supply the &#039;&#039;&#039;-L&#039;&#039;&#039; switch. The group and volumes created by the script will have the following names:&lt;br /&gt;
&lt;br /&gt;
* volume group: &#039;&#039;&#039;vg0&#039;&#039;&#039;&lt;br /&gt;
* swap volume: &#039;&#039;&#039;lv_swap&#039;&#039;&#039; (only created when swap size &amp;gt; 0)&lt;br /&gt;
* root volume: &#039;&#039;&#039;lv_root&#039;&#039;&#039; (only created when &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected)&lt;br /&gt;
* var volume: &#039;&#039;&#039;lv_var&#039;&#039;&#039; (only created when &#039;&#039;&#039;-m data&#039;&#039;&#039; is specified or interactively selected); also these volumes are currently always formatted as ext4.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lv_var&#039;&#039;&#039; or &#039;&#039;&#039;lv_root&#039;&#039;&#039; volumes are created to occupy all remaining space in the volume group.&lt;br /&gt;
&lt;br /&gt;
If you need to change any of these settings, you can use &amp;lt;code&amp;gt;vgrename&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lvrename&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lvreduce&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;lvresize&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you instead want to build your LVM system manually, see [[Setting up Logical Volumes with LVM]]. Then format and mount the disks, and supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=Setup-Disk Usage=&lt;br /&gt;
&lt;br /&gt;
usage: setup-disk [-hqr] [-k kernelflavor] [-m MODE] [-o apkovl] [-s SWAPSIZE]&lt;br /&gt;
		  [MOUNTPOINT | DISKDEV...]&lt;br /&gt;
&lt;br /&gt;
Install alpine on harddisk.&lt;br /&gt;
&lt;br /&gt;
If MOUNTPOINT is specified, then do a traditional disk install with MOUNTPOINT&lt;br /&gt;
as root.&lt;br /&gt;
&lt;br /&gt;
If DISKDEV is specified, then use the specified disk(s) without asking. If&lt;br /&gt;
multiple disks are specified then set them up in a RAID array. If there are&lt;br /&gt;
mode than 2 disks, then use raid level 5 instead of raid level 1.&lt;br /&gt;
&lt;br /&gt;
options:&lt;br /&gt;
 -h  Show this help&lt;br /&gt;
 -m  Use disk for MODE without asking, where MODE is either &#039;data&#039; or &#039;root&#039;&lt;br /&gt;
 -o  Restore system from given apkovl file&lt;br /&gt;
 -k  Use kernelflavor instead of $KERNEL_FLAVOR&lt;br /&gt;
 -L  Use LVM to manage partitions&lt;br /&gt;
 -q  Exit quietly if no disks are found&lt;br /&gt;
 -r  Enable software RAID1 with single disk&lt;br /&gt;
 -s  Use SWAPSIZE MB instead of $SWAP_SIZE MB for swap (Use 0 to disable swap)&lt;br /&gt;
 -v  Be more verbose about what is happening&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Disk Install Styles==&lt;br /&gt;
&lt;br /&gt;
You can select between &#039;sys&#039; or &#039;data&#039;.&lt;br /&gt;
&lt;br /&gt;
sys:&lt;br /&gt;
  This mode is a traditional disk install. The following partitions will be&lt;br /&gt;
  created on the disk: /boot, / (filesystem root) and swap.&lt;br /&gt;
    &lt;br /&gt;
  This mode may be used for development boxes, desktops, virtual servers, etc.&lt;br /&gt;
&lt;br /&gt;
data:&lt;br /&gt;
  This mode uses your disk(s) for data storage, not for the operating system.&lt;br /&gt;
  The system itself will run from tmpfs (RAM).&lt;br /&gt;
&lt;br /&gt;
  Use this mode if you only want to use the disk(s) for a mailspool, databases,&lt;br /&gt;
  logs, etc.&lt;br /&gt;
&lt;br /&gt;
none:&lt;br /&gt;
  Run without installing to disk.&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-bootable ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
Its purpose is to create media that boots into tmpfs by copying the contents of an ISO onto a USB key, CF, or similar media.&lt;br /&gt;
&lt;br /&gt;
For a higher-level walkthrough, see [[Create a Bootable USB#Creating_a_bootable_Alpine_Linux_USB_Stick_from_the_command_line|Creating a bootable Alpine Linux USB Stick from the command line]].&lt;br /&gt;
&lt;br /&gt;
This script accepts the following arguments and command-line switches (you can run &amp;lt;code&amp;gt;setup-bootable -h&amp;lt;/code&amp;gt; to see a usage message).&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-bootable &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; [&amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt;]}}&lt;br /&gt;
&lt;br /&gt;
The argument &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; can be a directory or an ISO (will be mounted to &amp;lt;code&amp;gt;MNT&amp;lt;/code&amp;gt; or {{Path|/mnt}}) or a URL (will be downloaded with &amp;lt;code&amp;gt;WGET&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;wget&amp;lt;/code&amp;gt;). The argument &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; can be a directory mountpoint, or will default to {{Path|/media/usb}} if not supplied.&lt;br /&gt;
&lt;br /&gt;
{{Define|-k|Keep alpine_dev in {{Path|syslinux.cfg}}; otherwise, replace with UUID.}}&lt;br /&gt;
{{Define|-u|Upgrade mode: keep existing {{Path|syslinux.cfg}} and don&#039;t run &amp;lt;code&amp;gt;syslinux&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Define|-f|Overwrite {{Path|syslinux.cfg}} even if &#039;&#039;&#039;-u&#039;&#039;&#039; was specified.}}&lt;br /&gt;
{{Define|-s|Force the running of &amp;lt;code&amp;gt;syslinux&amp;lt;/code&amp;gt; even if &#039;&#039;&#039;-u&#039;&#039;&#039; was specified.}}&lt;br /&gt;
{{Define|-v|Verbose mode}}&lt;br /&gt;
&lt;br /&gt;
The script will ensure that &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; and &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; are available; will copy the contents of &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; to &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt;, ensuring first that there&#039;s enough space; and unless &#039;&#039;&#039;-u&#039;&#039;&#039; was specified, will make &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; bootable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== setup-cryptswap ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-cryptswap&amp;lt;/code&amp;gt; [&amp;lt;var&amp;gt;partition&amp;lt;/var&amp;gt; | none]&lt;br /&gt;
&lt;br /&gt;
{{Todo|Does this script still work? At what stage can it be run: only after setup-alpine?}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-xorg-base ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
Installs the following packages: &amp;lt;code&amp;gt;xorg-server xf86-video-vesa xf86-input-evdev xf86-input-mouse xf86-input-keyboard udev&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Additional packages can be supplied as arguments to &amp;lt;code&amp;gt;setup-xorg-base&amp;lt;/code&amp;gt;. You might need, for example, some of: &amp;lt;code&amp;gt;xf86-input-synaptics xf86-video-&amp;lt;var&amp;gt;something&amp;lt;/var&amp;gt; xinit&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Documentation needed ==&lt;br /&gt;
&lt;br /&gt;
=== setup-xen-dom0 ===&lt;br /&gt;
&lt;br /&gt;
=== setup-gparted-desktop ===&lt;br /&gt;
Uses openbox.&lt;br /&gt;
&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
=== setup-mta ===&lt;br /&gt;
Uses ssmtp.&lt;br /&gt;
&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
=== setup-acf ===&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
This script was named &amp;lt;code&amp;gt;setup-webconf&amp;lt;/code&amp;gt; before Alpine 1.9 beta 4.&lt;br /&gt;
&lt;br /&gt;
See [[:Category:ACF|ACF pages]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== setup-ntp ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_configuration_management_scripts&amp;diff=10003</id>
		<title>Alpine configuration management scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_configuration_management_scripts&amp;diff=10003"/>
		<updated>2014-06-09T15:05:15Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* setup-sshd */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page summarizes the low-level behavior of the {{Path|/sbin/setup-*}} scripts on the Alpine ISO (and in a normal Alpine install).&lt;br /&gt;
&lt;br /&gt;
== setup-alpine ==&lt;br /&gt;
&lt;br /&gt;
For a higher-level walkthrough (using the &amp;quot;sys&amp;quot; installmode), see [[Install to disk|Basic HDD install]].&lt;br /&gt;
&lt;br /&gt;
This script accepts the following command-line switches (you can run &amp;lt;code&amp;gt;setup-alpine -h&amp;lt;/code&amp;gt; to see a usage message).&lt;br /&gt;
&lt;br /&gt;
{{Define|-a|Create an overlay file: this creates a temporary directory and saves its location in ROOT; however, the script doesn&#039;t export this variable so I think this feature isn&#039;t currently functional.}}&lt;br /&gt;
;-c &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&lt;br /&gt;
:Create a new &amp;quot;answerfile&amp;quot;, with default choices. You can edit the file and then invoke &amp;lt;code&amp;gt;setup-alpine -f &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
;-f &amp;lt;var&amp;gt;answerfile&amp;lt;/var&amp;gt;&lt;br /&gt;
:Use an existing &amp;quot;answerfile&amp;quot;, which may override some or all of the interactive prompts.&lt;br /&gt;
{{Define|-q|Run in &amp;quot;quick mode.&amp;quot; See below for details.}}&lt;br /&gt;
&lt;br /&gt;
The script&#039;s behavior is to do the following, in order. Bracketed options represent extra configuration choices that can be supplied when running the auxiliary setup scripts manually, or by supplying an &amp;quot;answerfile&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;setup-keymap&amp;lt;/code&amp;gt; [us us]&lt;br /&gt;
# [[#setup-hostname|setup-hostname]] [-n alpine-test]&lt;br /&gt;
# [[#setup-interfaces|setup-interfaces]] [-i &amp;lt; interfaces-file]&lt;br /&gt;
# &amp;lt;code&amp;gt;/etc/init.d/networking --quiet start &amp;amp;&amp;lt;/code&amp;gt;&lt;br /&gt;
# if none of the networking interfaces were configured using dhcp, then: [[#setup-dns|setup-dns]] [-d example.com -n &amp;quot;8.8.8.8 [...]&amp;quot;]&lt;br /&gt;
# set the root password&lt;br /&gt;
# if not in quick mode, then: [[#setup-timezone|setup-timezone]] [-z UTC | -z America/New_York | -p EST+5]&lt;br /&gt;
# enable the new hostname (&amp;lt;code&amp;gt;/etc/init.d/hostname --quiet restart&amp;lt;/code&amp;gt;)&lt;br /&gt;
# add &amp;lt;code&amp;gt;networking&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;urandom&amp;lt;/code&amp;gt; to the &#039;&#039;&#039;boot&#039;&#039;&#039; rc level, and &amp;lt;code&amp;gt;acpid&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cron&amp;lt;/code&amp;gt; to the &#039;&#039;&#039;default&#039;&#039;&#039; rc level, and start the &#039;&#039;&#039;boot&#039;&#039;&#039; and &#039;&#039;&#039;default&#039;&#039;&#039; rc services&lt;br /&gt;
# extract the fully-qualified domain name and hostname from {{Path|/etc/resolv.conf}} and &amp;lt;code&amp;gt;hostname&amp;lt;/code&amp;gt;, and update {{Path|/etc/hosts}}&lt;br /&gt;
# [[#setup-proxy|setup-proxy]] [-q &amp;lt;nowiki&amp;gt;&amp;quot;http://webproxy:8080&amp;quot;&amp;lt;/nowiki&amp;gt;], and activate proxy if it was configured&lt;br /&gt;
# &amp;lt;code&amp;gt;setup-apkrepos&amp;lt;/code&amp;gt; [-r (to select a mirror randomly)]&lt;br /&gt;
# if not in quick mode, then: [[#setup-sshd|setup-sshd]] [-c openssh | dropbear | none]&lt;br /&gt;
# if not in quick mode, then: &amp;lt;code&amp;gt;setup-ntp&amp;lt;/code&amp;gt; [-c chrony | openntpd | none]&lt;br /&gt;
# if not in quick mode, then: &amp;lt;code&amp;gt;DEFAULT_DISK=none&amp;lt;/code&amp;gt; [[#setup-disk|setup-disk]] &amp;lt;code&amp;gt;-q&amp;lt;/code&amp;gt; [-m data /dev/sda]&lt;br /&gt;
# if installation mode selected during setup-disk was &amp;quot;data&amp;quot; instead of &amp;quot;sys&amp;quot;, then: &amp;lt;code&amp;gt;setup-lbu&amp;lt;/code&amp;gt; [/media/sdb1]&lt;br /&gt;
# if installation mode selected during setup-disk was &amp;quot;data&amp;quot; instead of &amp;quot;sys&amp;quot;, then: &amp;lt;code&amp;gt;setup-apkcache&amp;lt;/code&amp;gt; [/media/sdb1/cache | none]&lt;br /&gt;
&lt;br /&gt;
== setup-hostname ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-hostname&amp;lt;/code&amp;gt; [-h] [-n hostname]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-n&#039;&#039;&#039; &amp;lt;var&amp;gt;Specify hostname&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This script allows quick and easy setup of the system hostname by writing it to {{Path|/etc/hostname}}.  The script prevents you from writing an invalid hostname (such as one that used invalid characters or starts with a &#039;-&#039; or is too long).&lt;br /&gt;
The script can be invoked manually or is called as part of the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
== setup-interfaces ==&lt;br /&gt;
{{Cmd|setup-interfaces [-i &amp;amp;lt; &amp;lt;var&amp;gt;interfaces-file&amp;lt;/var&amp;gt;]}}&lt;br /&gt;
&lt;br /&gt;
Note that the contents of &amp;lt;var&amp;gt;interfaces-file&amp;lt;/var&amp;gt; has to be supplied as stdin, rather than naming the file as an additional argument. The contents should have the format of {{Path|/etc/network/interfaces}}, such as:&lt;br /&gt;
&lt;br /&gt;
 auto lo&lt;br /&gt;
 iface lo inet loopback&lt;br /&gt;
 &lt;br /&gt;
 auto eth0&lt;br /&gt;
 iface eth0 inet dhcp&lt;br /&gt;
     hostname alpine-test&lt;br /&gt;
&lt;br /&gt;
== setup-dns ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-dns&amp;lt;/code&amp;gt; [-h] [-d domain name] [-n name server]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-d&#039;&#039;&#039; &amp;lt;var&amp;gt;specify search domain name&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-n&#039;&#039;&#039; &amp;lt;var&amp;gt;name server IP&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The setup-dns script is stored in {{Path|/sbin/setup-dns}} and allows quick and simple setup of DNS servers (and a DNS search domain if required).  Simply running &amp;lt;code&amp;gt;setup-dns&amp;lt;/code&amp;gt; will allow interactive use of the script, or the options can be specified.&lt;br /&gt;
&lt;br /&gt;
The information fed to this script is written to {{Path|/etc/resolv.conf}}&lt;br /&gt;
&lt;br /&gt;
Example usage: {{Cmd|setup-dns -d example.org -n 8.8.8.8}}&lt;br /&gt;
&lt;br /&gt;
Example {{Path|/etc/resolv.conf}}:&lt;br /&gt;
&lt;br /&gt;
 search example.org&lt;br /&gt;
 nameserver 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
It can be run manually but is also invoked in the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script unless interfaces are configured for DHCP.&lt;br /&gt;
&lt;br /&gt;
== setup-timezone ==&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-timezone&amp;lt;/code&amp;gt; [-z UTC | -z America/New_York | -p EST+5]&lt;br /&gt;
&lt;br /&gt;
Can pre-select the timezone using either of these switches:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-z&#039;&#039;&#039; &amp;lt;var&amp;gt;subfolder of&amp;lt;/var&amp;gt; {{Path|/usr/share/zoneinfo}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-p&#039;&#039;&#039; &amp;lt;var&amp;gt;POSIX TZ format&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-proxy ==&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-proxy&amp;lt;/code&amp;gt; [-hq] [PROXYURL]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-q&#039;&#039;&#039; &amp;lt;var&amp;gt;Quiet mode&amp;lt;/var&amp;gt; prevents changes from taking effect until after reboot&lt;br /&gt;
&lt;br /&gt;
This script requests the system proxy to use in the form &amp;lt;code&amp;gt;http://&amp;lt;proxyurl&amp;gt;:&amp;lt;port&amp;gt;&amp;lt;/code&amp;gt; for example:&lt;br /&gt;
&amp;lt;code&amp;gt;http://10.0.0.1:8080&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set no system proxy use &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt;.&lt;br /&gt;
This script exports the following environmental variables: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;http_proxy=$proxyurl&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;https_proxy=$proxyurl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ftp_proxy=$proxyurl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;$proxyurl&amp;lt;/code&amp;gt; is the value input.  &lt;br /&gt;
If &amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt; was chosen then the value it is set to a blank value (and so no proxy is used).&lt;br /&gt;
&lt;br /&gt;
== setup-sshd ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-sshd&amp;lt;/code&amp;gt; [-h] [-c choice of SSH daemon]&lt;br /&gt;
&lt;br /&gt;
Options:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-h&#039;&#039;&#039; &amp;lt;var&amp;gt;Show help&amp;lt;/var&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;-c&#039;&#039;&#039; &amp;lt;var&amp;gt;SSH daemon&amp;lt;/var&amp;gt; where SSH daemon can be one of the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;openssh&amp;lt;/code&amp;gt; install the {{Pkg|openSSH}} daemon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;dropbear&amp;lt;/code&amp;gt; install the {{Pkg|dropbear}} daemon&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;none&amp;lt;/code&amp;gt; Do not install an SSH daemon&lt;br /&gt;
&lt;br /&gt;
Example usage: {{Cmd|setup-sshd -c dropbear}}&lt;br /&gt;
&lt;br /&gt;
The setup-sshd script is stored in {{Path|/sbin/setup-sshd}} and allows quick and simple setup of either the OpenSSH or Dropbear SSH daemon &amp;amp; client. &lt;br /&gt;
It can be run manually but is also invoked in the &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
== setup-disk ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;DEFAULT_DISK=none setup-disk -q&amp;lt;/code&amp;gt; [-m data | sys] [&amp;lt;var&amp;gt;mountpoint directory&amp;lt;/var&amp;gt; | /dev/sda ...]&lt;br /&gt;
&lt;br /&gt;
This script accepts the following command-line switches:&lt;br /&gt;
&lt;br /&gt;
;-k &amp;lt;var&amp;gt;kernel flavor&amp;lt;/var&amp;gt;&lt;br /&gt;
;-o &amp;lt;var&amp;gt;apkovl file&amp;lt;/var&amp;gt;&lt;br /&gt;
:Restore system from &amp;lt;var&amp;gt;apkovl file&amp;lt;/var&amp;gt;&lt;br /&gt;
;-m data | sys&lt;br /&gt;
:Don&#039;t prompt for installation mode. With &#039;&#039;&#039;-m data&#039;&#039;&#039;, the supplied devices are formatted to use as a {{Path|/var}} volume.&lt;br /&gt;
{{Define|-r|Use RAID1 with a single disk (degraded mode)}}&lt;br /&gt;
{{Define|-L|Create and use volumes in a LVM group}}&lt;br /&gt;
;-s &amp;lt;var&amp;gt;swap size in MB&amp;lt;/var&amp;gt;&lt;br /&gt;
:Use 0 to disable swap&lt;br /&gt;
{{Define|-q|Exit quietly if no disks are found}}&lt;br /&gt;
{{Define|-v|Verbose mode}}&lt;br /&gt;
&lt;br /&gt;
The script also honors the following environment variables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BOOT_SIZE&amp;lt;/code&amp;gt;&lt;br /&gt;
:Size of the boot partition in MB; defaults to 100. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SWAP_SIZE&amp;lt;/code&amp;gt;&lt;br /&gt;
:Size of the swap volume in MB; set to 0 to disable swap. If not specified, will default to twice RAM, up to 4096, but won&#039;t be more than 1/3 the size of the smallest disk, and if less than 64 will just be 0. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;ROOTFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the / volume; defaults to ext4. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BOOTFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the /boot volume; defaults to ext4. Only used if &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;VARFS&amp;lt;/code&amp;gt;&lt;br /&gt;
:Filesystem to use for the /var volume; defaults to ext4. Only used if &#039;&#039;&#039;-m data&#039;&#039;&#039; is specified or interactively selected. Supported filesystems are: ext2 ext3 ext4 btrfs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SYSROOT&amp;lt;/code&amp;gt;&lt;br /&gt;
:Mountpoint to use when creating volumes and doing traditional disk install (&#039;&#039;&#039;-m data&#039;&#039;&#039;). Defaults to {{Path|/mnt}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;MBR&amp;lt;/code&amp;gt;&lt;br /&gt;
:Path of MBR binary code, defaults to {{Path|/usr/share/syslinux/mbr.bin}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Writes to /tmp/ovlfiles, /tmp/alpine-install-diskmode.out, and /tmp/sfdisk.out but that never seems to be used elsewhere. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Partitioning ===&lt;br /&gt;
&lt;br /&gt;
If you have complex partitioning needs, you can partition, format, and mount your volumes manually, then just supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;. Doing so implicitly behaves as though &#039;&#039;&#039;-m sys&#039;&#039;&#039; had also been specified.&lt;br /&gt;
&lt;br /&gt;
See [[Setting up disks manually]] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== RAID ====&lt;br /&gt;
&amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; will automatically build a RAID array if you supply the &#039;&#039;&#039;-r&#039;&#039;&#039; switch, or if you specify more than one device. The array will always be [https://en.m.wikipedia.org/wiki/Standard_RAID_levels#RAID_1 RAID1] (and [https://raid.wiki.kernel.org/index.php/RAID_superblock_formats#The_version-0.90_Superblock_Format --metadata=0.90]) for the /boot volumes, but will be [https://en.m.wikipedia.org/wiki/Standard_RAID_levels#RAID_5 RAID5] (and [https://raid.wiki.kernel.org/index.php/RAID_superblock_formats#The_version-1_Superblock_Format --metadata=1.2] for non-boot volumes when 3 or more devices are supplied.&lt;br /&gt;
&lt;br /&gt;
If you instead want to build your RAID array manually, see [[Setting up a software RAID1 array]]. Then format and mount the disks, and supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== LVM ====&lt;br /&gt;
&amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; will automatically build and use volumes in a LVM group if you supply the &#039;&#039;&#039;-L&#039;&#039;&#039; switch. The group and volumes created by the script will have the following names:&lt;br /&gt;
&lt;br /&gt;
* volume group: &#039;&#039;&#039;vg0&#039;&#039;&#039;&lt;br /&gt;
* swap volume: &#039;&#039;&#039;lv_swap&#039;&#039;&#039; (only created when swap size &amp;gt; 0)&lt;br /&gt;
* root volume: &#039;&#039;&#039;lv_root&#039;&#039;&#039; (only created when &#039;&#039;&#039;-m sys&#039;&#039;&#039; is specified or interactively selected)&lt;br /&gt;
* var volume: &#039;&#039;&#039;lv_var&#039;&#039;&#039; (only created when &#039;&#039;&#039;-m data&#039;&#039;&#039; is specified or interactively selected); also these volumes are currently always formatted as ext4.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lv_var&#039;&#039;&#039; or &#039;&#039;&#039;lv_root&#039;&#039;&#039; volumes are created to occupy all remaining space in the volume group.&lt;br /&gt;
&lt;br /&gt;
If you need to change any of these settings, you can use &amp;lt;code&amp;gt;vgrename&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lvrename&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lvreduce&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;lvresize&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you instead want to build your LVM system manually, see [[Setting up Logical Volumes with LVM]]. Then format and mount the disks, and supply the root mountpoint to &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=Setup-Disk Usage=&lt;br /&gt;
&lt;br /&gt;
usage: setup-disk [-hqr] [-k kernelflavor] [-m MODE] [-o apkovl] [-s SWAPSIZE]&lt;br /&gt;
		  [MOUNTPOINT | DISKDEV...]&lt;br /&gt;
&lt;br /&gt;
Install alpine on harddisk.&lt;br /&gt;
&lt;br /&gt;
If MOUNTPOINT is specified, then do a traditional disk install with MOUNTPOINT&lt;br /&gt;
as root.&lt;br /&gt;
&lt;br /&gt;
If DISKDEV is specified, then use the specified disk(s) without asking. If&lt;br /&gt;
multiple disks are specified then set them up in a RAID array. If there are&lt;br /&gt;
mode than 2 disks, then use raid level 5 instead of raid level 1.&lt;br /&gt;
&lt;br /&gt;
options:&lt;br /&gt;
 -h  Show this help&lt;br /&gt;
 -m  Use disk for MODE without asking, where MODE is either &#039;data&#039; or &#039;root&#039;&lt;br /&gt;
 -o  Restore system from given apkovl file&lt;br /&gt;
 -k  Use kernelflavor instead of $KERNEL_FLAVOR&lt;br /&gt;
 -L  Use LVM to manage partitions&lt;br /&gt;
 -q  Exit quietly if no disks are found&lt;br /&gt;
 -r  Enable software RAID1 with single disk&lt;br /&gt;
 -s  Use SWAPSIZE MB instead of $SWAP_SIZE MB for swap (Use 0 to disable swap)&lt;br /&gt;
 -v  Be more verbose about what is happening&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Disk Install Styles==&lt;br /&gt;
&lt;br /&gt;
You can select between &#039;sys&#039; or &#039;data&#039;.&lt;br /&gt;
&lt;br /&gt;
sys:&lt;br /&gt;
  This mode is a traditional disk install. The following partitions will be&lt;br /&gt;
  created on the disk: /boot, / (filesystem root) and swap.&lt;br /&gt;
    &lt;br /&gt;
  This mode may be used for development boxes, desktops, virtual servers, etc.&lt;br /&gt;
&lt;br /&gt;
data:&lt;br /&gt;
  This mode uses your disk(s) for data storage, not for the operating system.&lt;br /&gt;
  The system itself will run from tmpfs (RAM).&lt;br /&gt;
&lt;br /&gt;
  Use this mode if you only want to use the disk(s) for a mailspool, databases,&lt;br /&gt;
  logs, etc.&lt;br /&gt;
&lt;br /&gt;
none:&lt;br /&gt;
  Run without installing to disk.&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-bootable ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
Its purpose is to create media that boots into tmpfs by copying the contents of an ISO onto a USB key, CF, or similar media.&lt;br /&gt;
&lt;br /&gt;
For a higher-level walkthrough, see [[Create a Bootable USB#Creating_a_bootable_Alpine_Linux_USB_Stick_from_the_command_line|Creating a bootable Alpine Linux USB Stick from the command line]].&lt;br /&gt;
&lt;br /&gt;
This script accepts the following arguments and command-line switches (you can run &amp;lt;code&amp;gt;setup-bootable -h&amp;lt;/code&amp;gt; to see a usage message).&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-bootable &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; [&amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt;]}}&lt;br /&gt;
&lt;br /&gt;
The argument &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; can be a directory or an ISO (will be mounted to &amp;lt;code&amp;gt;MNT&amp;lt;/code&amp;gt; or {{Path|/mnt}}) or a URL (will be downloaded with &amp;lt;code&amp;gt;WGET&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;wget&amp;lt;/code&amp;gt;). The argument &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; can be a directory mountpoint, or will default to {{Path|/media/usb}} if not supplied.&lt;br /&gt;
&lt;br /&gt;
{{Define|-k|Keep alpine_dev in {{Path|syslinux.cfg}}; otherwise, replace with UUID.}}&lt;br /&gt;
{{Define|-u|Upgrade mode: keep existing {{Path|syslinux.cfg}} and don&#039;t run &amp;lt;code&amp;gt;syslinux&amp;lt;/code&amp;gt;}}&lt;br /&gt;
{{Define|-f|Overwrite {{Path|syslinux.cfg}} even if &#039;&#039;&#039;-u&#039;&#039;&#039; was specified.}}&lt;br /&gt;
{{Define|-s|Force the running of &amp;lt;code&amp;gt;syslinux&amp;lt;/code&amp;gt; even if &#039;&#039;&#039;-u&#039;&#039;&#039; was specified.}}&lt;br /&gt;
{{Define|-v|Verbose mode}}&lt;br /&gt;
&lt;br /&gt;
The script will ensure that &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; and &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; are available; will copy the contents of &amp;lt;var&amp;gt;source&amp;lt;/var&amp;gt; to &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt;, ensuring first that there&#039;s enough space; and unless &#039;&#039;&#039;-u&#039;&#039;&#039; was specified, will make &amp;lt;var&amp;gt;dest&amp;lt;/var&amp;gt; bootable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== setup-cryptswap ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;setup-cryptswap&amp;lt;/code&amp;gt; [&amp;lt;var&amp;gt;partition&amp;lt;/var&amp;gt; | none]&lt;br /&gt;
&lt;br /&gt;
{{Todo|Does this script still work? At what stage can it be run: only after setup-alpine?}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== setup-xorg-base ==&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
Installs the following packages: &amp;lt;code&amp;gt;xorg-server xf86-video-vesa xf86-input-evdev xf86-input-mouse xf86-input-keyboard udev&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Additional packages can be supplied as arguments to &amp;lt;code&amp;gt;setup-xorg-base&amp;lt;/code&amp;gt;. You might need, for example, some of: &amp;lt;code&amp;gt;xf86-input-synaptics xf86-video-&amp;lt;var&amp;gt;something&amp;lt;/var&amp;gt; xinit&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Documentation needed ==&lt;br /&gt;
&lt;br /&gt;
=== setup-xen-dom0 ===&lt;br /&gt;
&lt;br /&gt;
=== setup-gparted-desktop ===&lt;br /&gt;
Uses openbox.&lt;br /&gt;
&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
=== setup-mta ===&lt;br /&gt;
Uses ssmtp.&lt;br /&gt;
&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
=== setup-acf ===&lt;br /&gt;
This is a standalone script; it&#039;s not invoked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; but must be run manually.&lt;br /&gt;
&lt;br /&gt;
This script was named &amp;lt;code&amp;gt;setup-webconf&amp;lt;/code&amp;gt; before Alpine 1.9 beta 4.&lt;br /&gt;
&lt;br /&gt;
See [[:Category:ACF|ACF pages]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== setup-ntp ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10002</id>
		<title>Setting up Explicit Squid Proxy</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_Explicit_Squid_Proxy&amp;diff=10002"/>
		<updated>2014-06-05T19:33:33Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: Tidying of /* Blocking domains */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.squid-cache.org/ Squid] is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It is licensed under the [https://gnu.org/licenses/gpl.html GNU GPL]. &lt;br /&gt;
&lt;br /&gt;
If you are looking to setup a transparent squid proxy, see [[Setting up Transparent Squid Proxy|this page]]&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
=== client ===&lt;br /&gt;
A client is often considered a user of a PC or similar system, but more accurately a client is the applications a person uses to access web pages and other resources, and the OS they are running on.&lt;br /&gt;
&lt;br /&gt;
=== proxy ===&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Proxy_server proxy] is a device which makes connections on behalf of clients.  If we consider a common [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection, there is one [http://en.wikipedia.org/wiki/Transmission_Control_Protocol TCP] connection between the client (source) and the proxy, and a separate TCP connection between the proxy and the server (destination).  Consider this beautiful diagram:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Client&amp;lt;----------&amp;gt;|PROXY|&amp;lt;------------&amp;gt;Server&lt;br /&gt;
	   A			B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Point &#039;&#039;&#039;A&#039;&#039;&#039; is the &#039;&#039;&#039;client-side connection&#039;&#039;&#039; and point &#039;&#039;&#039;B&#039;&#039;&#039; is the &#039;&#039;&#039;server-side connection&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These are separate, distinct connections, so for example the client-side could be encrypted and the server-side in plaintext (unencrypted), or the client-side could use browser user-agent header &#039;&#039;x&#039;&#039; and the server-side connection could use browser user-agent header &#039;&#039;y&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The proxy is effectively acting as a server to the client, and as a client to the server (OCS).  Without a proxy, the connection would simply be from client to server.  The destination server is often referred to as the &#039;OCS&#039; or &#039;Origin Content Server&#039; - this simply means the server hosting the objects that the client requests (for example the web pages that you want).&lt;br /&gt;
&lt;br /&gt;
The above is of course a simplified version of things.  Other factors, such as the HTTP version of the client browser, or existence of the object in cache on the proxy, will have impacts on how many server-side connections are created.&lt;br /&gt;
		&lt;br /&gt;
==== explicit forward proxy ====&lt;br /&gt;
An explicit proxy is one in which the client is &#039;&#039;explicitly configured&#039;&#039; to use the proxy, and as such are aware of the existence of the proxy on the network.  When the client sends packets to an explicit proxy, they are addressed to the proxy server listening address and port.&lt;br /&gt;
Squid usually listens for explicit traffic on TCP port 3128 but TCP port 8080 is a common explicit proxy listening port.  AFAIK all explicit proxy deployments are forward proxy deployments, where the clients can make use of the caching and optimisation features of the proxy when making outbound requests.  An explicit proxy can be involved in authentication of the client.&lt;br /&gt;
&#039;&#039;This article discusses this type of proxy deployment.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== [[Setting up Transparent Squid Proxy|transparent]] forward proxy ====&lt;br /&gt;
A transparent proxy, also known as an intercepting proxy, does not require any configuration changes on the client, since traffic is &#039;&#039;transparently&#039;&#039; sent to the proxy, usually through traffic redirection by a router.  When the client sends packets, they are addressed to the destination server.  A transparent server cannot be involved with client authentication; a client cannot authenticate to a proxy server that it is not (or should not) be aware of.&lt;br /&gt;
&lt;br /&gt;
==== reverse proxy ====&lt;br /&gt;
A [https://en.wikipedia.org/wiki/Reverse_proxy reverse proxy] sits in front of a resource such as a web server and answers queries from clients, caching content from the server and optimising connections to it.&lt;br /&gt;
&lt;br /&gt;
=== cache ===&lt;br /&gt;
A cache is simply an object store.  A proxy will usually cache objects (images, html text, downloaded files etc) that are requested by clients, which means storing the objects on the proxy either in RAM or on disk.&lt;br /&gt;
This has the benefit of a client being able to get the object from the proxy, without having to wait for the proxy to connect out to the destination server (OCS) and download the object again, resulting in a better client experience (&amp;quot;the web pages seem to load faster&amp;quot;) and reduced bandwidth (less connections made server side, especially if we consider objects that are repeatedly requested).&lt;br /&gt;
&lt;br /&gt;
Caching is influenced by proxy configuration (what to cache) and by numerous [https://en.wikipedia.org/wiki/HTTP_header HTTP headers] (am I allowed to cache this object?  How long should I cache it for?) such as &#039;Expires&#039;, &#039;Cache Control&#039;, &#039;If-Modified-Since&#039; and &#039;Last-Modified&#039;.&lt;br /&gt;
A proxy will usually keep its cache fresh by making requests for cached objects independent of client requests for the objects.&lt;br /&gt;
&lt;br /&gt;
=== More information ===&lt;br /&gt;
You may also wish to review https://devcentral.f5.com/articles/the-concise-guide-to-proxies which provides further information on various proxy types.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the {{Pkg|squid}} package:&lt;br /&gt;
{{Cmd|apk add squid}}&lt;br /&gt;
&lt;br /&gt;
If you wish to use the Alpine Configuration Framework (ACF) front-end for squid, install the {{Pkg|acf-squid}} package:&lt;br /&gt;
{{Cmd|apk add acf-squid}}&lt;br /&gt;
You can then logon to the device over https://x.x.x.x (replace x.x.x.x with the IP of your server of course) and manage the squid configuration files and stop/start/restart the daemon etc.&lt;br /&gt;
&lt;br /&gt;
== Basic configuration ==&lt;br /&gt;
=== Config file ===&lt;br /&gt;
The main configuration file is &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt;.  Lines beginning with a &#039;#&#039; are comments.&lt;br /&gt;
squid should already come with a basic working configuration file but an example configuration file is shown below, which will get you up and running quickly and is well commented but please change the localnet definition for a more restrictive one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Tested and working on squid 3.3.10-r0 and Alpine 2.7.1 (kernel 3.10.19-0-grsec), 64-bit&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt to list your (internal) IP networks from where browsing&lt;br /&gt;
## should be allowed&lt;br /&gt;
acl localnet src 10.0.0.0/8	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network&lt;br /&gt;
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network&lt;br /&gt;
## Allow anyone to use the proxy (you should lock this down to client networks only!):&lt;br /&gt;
# acl localnet src all&lt;br /&gt;
## IPv6 local addresses:&lt;br /&gt;
acl localnet src fc00::/7       # RFC 4193 local private network range&lt;br /&gt;
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines&lt;br /&gt;
&lt;br /&gt;
acl SSL_ports port 443&lt;br /&gt;
acl Safe_ports port 80		# http&lt;br /&gt;
acl Safe_ports port 21		# ftp&lt;br /&gt;
acl Safe_ports port 443		# https&lt;br /&gt;
acl Safe_ports port 70		# gopher&lt;br /&gt;
acl Safe_ports port 210		# waiss&lt;br /&gt;
acl Safe_ports port 1025-65535	# unregistered ports&lt;br /&gt;
acl Safe_ports port 280		# http-mgmt&lt;br /&gt;
acl Safe_ports port 488		# gss-http&lt;br /&gt;
acl Safe_ports port 591		# filemaker&lt;br /&gt;
acl Safe_ports port 777		# multiling http&lt;br /&gt;
acl CONNECT method CONNECT&lt;br /&gt;
acl QUERY urlpath_regex cgi-bin \? asp aspx jsp&lt;br /&gt;
&lt;br /&gt;
## Prevent caching jsp, cgi-bin etc&lt;br /&gt;
cache deny QUERY&lt;br /&gt;
&lt;br /&gt;
## Only allow access to the defined safe ports whitelist&lt;br /&gt;
http_access deny !Safe_ports&lt;br /&gt;
&lt;br /&gt;
## Deny CONNECT to other than secure SSL ports&lt;br /&gt;
http_access deny CONNECT !SSL_ports&lt;br /&gt;
&lt;br /&gt;
## Only allow cachemgr access from localhost&lt;br /&gt;
http_access allow localhost manager&lt;br /&gt;
http_access deny manager&lt;br /&gt;
&lt;br /&gt;
## We strongly recommend the following be uncommented to protect innocent&lt;br /&gt;
## web applications running on the proxy server who think the only&lt;br /&gt;
## one who can access services on &amp;quot;localhost&amp;quot; is a local user&lt;br /&gt;
http_access deny to_localhost&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
## Example rule allowing access from your local networks.&lt;br /&gt;
## Adapt localnet in the ACL section to list your (internal) IP networks&lt;br /&gt;
## from where browsing should be allowed&lt;br /&gt;
http_access allow localnet&lt;br /&gt;
http_access allow localhost&lt;br /&gt;
&lt;br /&gt;
## And finally deny all other access to this proxy&lt;br /&gt;
http_access deny all&lt;br /&gt;
&lt;br /&gt;
## Squid normally listens to port 3128&lt;br /&gt;
http_port 3128&lt;br /&gt;
## If you have multiple interfaces you can specify to listen on one IP like this:&lt;br /&gt;
#http_port 1.2.3.4:3128 &lt;br /&gt;
&lt;br /&gt;
## Uncomment and adjust the following to add a disk cache directory.&lt;br /&gt;
## 1024 is the disk space to use for cache in MB, adjust as you see fit!&lt;br /&gt;
## Default is no disk cache&lt;br /&gt;
#cache_dir ufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Better, use &#039;aufs&#039; cache type, see &lt;br /&gt;
##http://www.squid-cache.org/Doc/config/cache_dir/ for info.&lt;br /&gt;
#cache_dir aufs /var/cache/squid 1024 16 256&lt;br /&gt;
## Recommended to only change cache type when squid is stopped, and use &#039;squid -z&#039; to&lt;br /&gt;
## ensure cache is (re)created correctly&lt;br /&gt;
&lt;br /&gt;
## Leave coredumps in the first cache dir&lt;br /&gt;
#coredump_dir /var/cache/squid&lt;br /&gt;
&lt;br /&gt;
## Where does Squid log to?&lt;br /&gt;
#access_log /var/log/squid/access.log&lt;br /&gt;
## Use the below to turn off access logging&lt;br /&gt;
access_log none&lt;br /&gt;
## When logging, web auditors want to see the full uri, even with the query terms&lt;br /&gt;
#strip_query_terms off&lt;br /&gt;
## Keep 7 days of logs&lt;br /&gt;
#logfile_rotate 7&lt;br /&gt;
&lt;br /&gt;
## How much RAM, in MB, to use for cache? Default since squid 3.1 is 256 MB&lt;br /&gt;
cache_mem 64 MB&lt;br /&gt;
&lt;br /&gt;
## Maximum size of individual objects to store in cache&lt;br /&gt;
maximum_object_size 1 MB&lt;br /&gt;
&lt;br /&gt;
## Amount of data to buffer from server to client &lt;br /&gt;
read_ahead_gap 64 KB&lt;br /&gt;
&lt;br /&gt;
## Use X-Forwarded-For header?&lt;br /&gt;
## Some consider this a privacy/security risk so it is often disabled&lt;br /&gt;
## However it can be useful to identify misbehaving/problematic clients&lt;br /&gt;
#forwarded_for on &lt;br /&gt;
forwarded_for delete &lt;br /&gt;
&lt;br /&gt;
## Suppress sending squid version information&lt;br /&gt;
httpd_suppress_version_string on&lt;br /&gt;
&lt;br /&gt;
## How long to wait when shutting down squid&lt;br /&gt;
shutdown_lifetime 30 seconds&lt;br /&gt;
&lt;br /&gt;
## Replace the User Agent header.  Be sure to deny the header first, then replace it :)&lt;br /&gt;
#request_header_access User-Agent deny all&lt;br /&gt;
#request_header_replace User-Agent Mozilla/5.0 (Windows; MSIE 9.0; Windows NT 9.0; en-US)&lt;br /&gt;
&lt;br /&gt;
## What hostname to display? (defaults to system hostname)&lt;br /&gt;
#visible_hostname a_proxy&lt;br /&gt;
&lt;br /&gt;
## Use a different hosts file?&lt;br /&gt;
#hosts_file /path/to/file&lt;br /&gt;
&lt;br /&gt;
## Add any of your own refresh_pattern entries above these.&lt;br /&gt;
refresh_pattern ^ftp:		1440	20%	10080&lt;br /&gt;
refresh_pattern ^gopher:	1440	0%	1440&lt;br /&gt;
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0&lt;br /&gt;
refresh_pattern .		0	20%	4320&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you change the squid configuration file, you do not need to restart squid in order to load the changes, just use this command instead:&lt;br /&gt;
{{Cmd|squid -k reconfigure}}&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
==== Start and check squid ====&lt;br /&gt;
Start the squid service:&lt;br /&gt;
{{Cmd|rc-service squid start}}&lt;br /&gt;
&lt;br /&gt;
To start squid automatically at boot:&lt;br /&gt;
{{Cmd|rc-update add squid}}&lt;br /&gt;
&lt;br /&gt;
Check the squid configuration for errors:&lt;br /&gt;
{{Cmd|squid -k check}}&lt;br /&gt;
&lt;br /&gt;
If there is no feedback, everything is gravy! (that&#039;s a good thing).&lt;br /&gt;
&lt;br /&gt;
Check that squid is listening for traffic, using netstat for example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|netstat -tl}}&lt;br /&gt;
You should see a line showing a Local Address and the listening port (in our example config above it is set to 3128).  If you don&#039;t see this, check the &amp;quot;http_port&amp;quot; directive is set in the config file and has a value.  Ensure this port isn&#039;t being used by something else on the system.&lt;br /&gt;
&lt;br /&gt;
Remember to ensure the squid proxy has valid [[Configure Networking|IP configuration]] including default gateway etc.&lt;br /&gt;
&lt;br /&gt;
==== Configure the client ====&lt;br /&gt;
Each application using the proxy will have to be configured to send traffic via the proxy.  If we assume that our squid proxy is running on IP address 10.0.0.1, port 3128, we would configure the Firefox browser in the following manner:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Manual proxy configuration&#039;&#039;&#039; and tick the &#039;use this proxy server for all protocols&#039; box&lt;br /&gt;
* Under &#039;&#039;&#039;HTTP Proxy:&#039;&#039;&#039; add the squid listening IP address, 10.0.0.1.  In the &#039;&#039;&#039;Port:&#039;&#039;&#039; section add the squid listening port 3128&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
Now browse, you should have internet access, via the proxy!&lt;br /&gt;
&lt;br /&gt;
Many Operating Systems allow a system proxy to be set.  Firefox can be set to use the system proxy settings:&lt;br /&gt;
* &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Network&amp;gt;Settings...&#039;&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;&#039;Use system proxy settings&#039;&#039;&#039;&lt;br /&gt;
* Click &#039;&#039;&#039;OK&#039;&#039;&#039; to save the changes.&lt;br /&gt;
&lt;br /&gt;
The [https://wiki.archlinux.org/index.php/Proxy_settings system proxy settings] themselves vary from system to system but on an Alpine install you can simply run the [[Alpine Setup Scripts#setup-proxy|setup-proxy]] script.&lt;br /&gt;
&lt;br /&gt;
It is also possible to configure the browser to use a [https://en.wikipedia.org/wiki/Proxy_auto-config PAC file].  This file is usually hosted on a webserver (which may also be the proxy, but doesn&#039;t have to be) and it tells the browser what requests to send to the proxy and which ones to send direct (bypassing the proxy).&lt;br /&gt;
&lt;br /&gt;
The [http://wiki.squid-cache.org/SquidFaq/ConfiguringBrowsers Squid FAQ on configuring browsers] offers more information on this topic.&lt;br /&gt;
&lt;br /&gt;
==== Logs ====&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve set the proxy to take access logs, you can view these to see client requests coming in:&lt;br /&gt;
{{Cmd|tail -f /var/log/squid/access.log}}&lt;br /&gt;
Use Ctrl-C to exit back to the prompt.&lt;br /&gt;
&lt;br /&gt;
== SSL interception or SSL bumping ==&lt;br /&gt;
The offical squid documentation apears to prefer the term &#039;&#039;SSL interception&#039;&#039; for [[Setting up Transparent Squid Proxy|transparent]] squid deployments and &#039;&#039;SSL bumping&#039;&#039; for explicit proxy deployments.  Nonetheless, both environments use the [http://www.squid-cache.org/Doc/config/ssl_bump/ ssl_bump configuration directive] (and some others) in &amp;lt;code&amp;gt;/etc/squid/squid.conf&amp;lt;/code&amp;gt; for their configuration.&lt;br /&gt;
In general terminology, &#039;&#039;SSL interception&#039;&#039; is generally used to describe both deployments and that will be the term used here.  We are, of course, dealing with an &#039;&#039;explicit forward proxy&#039;&#039; configuration here.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour without SSL interception ====&lt;br /&gt;
Clients behind an explicit proxy use the [http://tools.ietf.org/rfc/rfc2817 &#039;CONNECT&#039;] HTTP method.  The first connection to the proxy port uses HTTP and specifies the destination server (often termed the Origin Content Server, or OCS).  After this the proxy simply acts as a [http://tools.ietf.org/id/draft-luotonen-web-proxy-tunneling-01.txt tunnel], and blindly proxies the connection without inspecting the traffic.&lt;br /&gt;
&lt;br /&gt;
==== Behaviour with SSL interception ====&lt;br /&gt;
Using this method, clients still use the [http://tools.ietf.org/rfc/rfc2817 CONNECT] method but the client uses the certificate from the proxy (so it must be a certificate trusted by the client) to encrypt the traffic.  Thus, the proxy is able to decrypt and view the traffic on the client-side before creating another encrypted connection server-side.  This enables the proxy to, in essence, launch a man-in-the-middle &#039;attack&#039; but also allows it to do all the things is can with plain, unencrypted HTTP traffic, like change the browser [https://en.wikipedia.org/wiki/User_agent User-Agent] reported to the server.&lt;br /&gt;
&lt;br /&gt;
==== Configuration ====&lt;br /&gt;
===== Add packages =====&lt;br /&gt;
Add the {{Pkg|ca-certificates}} package (required to trust common Certificate Authority (CA) certificates) and the {{Pkg|openssl}} package (to create self-signed certificate or CSR).  The &amp;lt;code&amp;gt;-U&amp;lt;/code&amp;gt; option ensures we update the package list first:&lt;br /&gt;
{{Cmd|apk -U add ca-certificates openssl}}&lt;br /&gt;
&lt;br /&gt;
===== Generate cert/key pair =====&lt;br /&gt;
You obviously don&#039;t need to follow &#039;&#039;both&#039;&#039; of the next sections.  Either generate a self-signed certificate or a CA signed one (you have to pay for the latter) and then amend the squid configuration to enable SSL interception and point it to the key/cert pair generated in these steps.&lt;br /&gt;
&lt;br /&gt;
====== Generate a self-signed certificate with OpenSSL ======&lt;br /&gt;
The following example command will produce a working cert/key pair, saved to {{Path|/etc/squid/squid.pem}}:&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:4096 -x509 -keyout /etc/squid/squid.pem -out /etc/squid/squid.pem -days 365 -nodes}}&lt;br /&gt;
Then adjust permissions:&lt;br /&gt;
{{Cmd|chmod 400 /etc/squid/squid.pem}}&lt;br /&gt;
In the above example we save the cetificate and key to the same file; they can be saved to separate files if you wish, just adjust paths accordingly.&lt;br /&gt;
====== Generate a CSR to get a CA-signed certificate ======&lt;br /&gt;
&lt;br /&gt;
Create a private key using the syntax &amp;lt;code&amp;gt;openssl genrsa -out &amp;lt;key_path_and_name&amp;gt; &amp;lt;keysize&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example: {{Cmd|openssl genrsa -out /etc/squid/squid.key 2048}}&lt;br /&gt;
&lt;br /&gt;
Create the CSR with the syntax &amp;lt;code&amp;gt;openssl req -new -key &amp;lt;key_path_and_name&amp;gt; -out &amp;lt;csr_path_and_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -new -key /etc/squid/squid.key -out /etc/squid/squid.csr}}&lt;br /&gt;
&lt;br /&gt;
You then need to supply the CSR (Certificate Signing Request) to your Certificate Authority (CA).  &#039;&#039;&#039;Do not send them, or anyone else, your private key.  It should remain private!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Some CA&#039;s (such as [http://www.thawte.nl/en/support/test+your+csr/ Thawte] and [https://ssl-tools.verisign.com/checker/ Verisign]) provide an online CSR checker, so you can ensure the CSR is valid before providing it to them.  &lt;br /&gt;
&lt;br /&gt;
Once the CA receive the CSR and do their thing they should send you back the CA signed public key.  Request it in .pem format if possible (it&#039;s a widely used standard for certs).  You then need to copy this back onto the Squid proxy, to {{Path|/etc/squid/}} if you are following the example here.&lt;br /&gt;
&lt;br /&gt;
Remember to [[Setting up Explicit Squid Proxy#Amend_.2Fetc.2Fsquid.2Fsquid.conf|amend the squid configuration]] to point at the correct locations of the private key and CA signed certificate.&lt;br /&gt;
&lt;br /&gt;
===== Amend /etc/squid/squid.conf =====&lt;br /&gt;
Next, we need to amend the squid configuration file to use SSL interception.  In the below example, we will add a few lines, then amend the &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; directive so that it still serves HTTP requests, but also performs SSL interception on HTTPS connections that are established via the HTTP method CONNECT.  You can use a separate &amp;lt;code&amp;gt;http_port&amp;lt;/code&amp;gt; for each if you wish, but remember to amend the client configuration to send HTTPS traffic to the alternative port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use the below to avoid proxy-chaining&lt;br /&gt;
always_direct allow all&lt;br /&gt;
## Always complete the server-side handshake before client-side (recommended)&lt;br /&gt;
ssl_bump server-first all&lt;br /&gt;
## Allow server side certificate errors such as untrusted certificates, otherwise the connection is closed for such errors&lt;br /&gt;
sslproxy_cert_error allow all&lt;br /&gt;
## Or maybe deny all server side certificate errors according to your company policy&lt;br /&gt;
#sslproxy_cert_error deny all&lt;br /&gt;
## Accept certificates that fail verification (should only be needed if using &#039;sslproxy_cert_error allow all&#039;)&lt;br /&gt;
sslproxy_flags DONT_VERIFY_PEER&lt;br /&gt;
&lt;br /&gt;
## Modify the http_port directive to perform SSL interception&lt;br /&gt;
## Ensure to point to the cert/key created earlier&lt;br /&gt;
## Disable SSLv2 because it isn&#039;t safe&lt;br /&gt;
http_port 3128 ssl-bump cert=/etc/squid/squid.pem key=/etc/squid/squid.pem generate-host-certificates=on options=NO_SSLv2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Fix client SSL Warnings =====&lt;br /&gt;
&lt;br /&gt;
You will need to install the self-signed proxy certificate (in our example we saved it to /etc/squid/squid.pem) to all clients, otherwise they will probably get an SSL error for every domain they visit over HTTPS.  It is important to install the certificate as a &#039;&#039;&#039;Certificate Authority&#039;&#039;&#039; (CA) certificate to the client browser for trust to establish properly.  If you are using a CA signed certificate (not a self-signed one) then the browser probably already trusts the certificate and so this step will likely not be needed.&lt;br /&gt;
&lt;br /&gt;
For Internet Explorer, you can likely double-click the .pem certificate and use the Certificate Import Wizard to manually install the certificate to the &#039;&#039;&#039;Trusted Root Certification Authorities&#039;&#039;&#039; certificate store.&lt;br /&gt;
&lt;br /&gt;
For Firefox, use &#039;&#039;&#039;Tools&amp;gt;Options&amp;gt;Advanced&amp;gt;Certificates&amp;gt;View Certificates.&#039;&#039;&#039; Under the &#039;&#039;&#039;Authorities&#039;&#039;&#039; tab, use &#039;&#039;&#039;Import...&#039;&#039;&#039; to add the certificate as a trusted authority.  Installing the certificate as any other kind of certificate will result in a poor user experience.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039;If you see the error &#039;&#039;This certificate is already installed as a certificate authority.&#039;&#039; be sure to check all locations for existence of the certificate and remove (delete) it wherever found.  Firefox likes to install certificates as &#039;&#039;&#039;Server&#039;&#039;&#039; certificates rather than under &#039;&#039;&#039;Authorities&#039;&#039;&#039; as we would like.  Once removing all traces of the certificate, please be sure to restart Firefox and try importing the certificate again.&lt;br /&gt;
&lt;br /&gt;
===== Disable SSL interception for certain sites =====&lt;br /&gt;
&lt;br /&gt;
There may be situations where you wish to disable SSL interception/SSL bumping for certain destinations due to issues with functionality or privacy concerns.  As an example, a Windows Dropbox client refused to establish a secure connection because it did not trust the self-signed certificate in use by the proxy.  Or, you may wish to allow user privacy to be retained when they are using hotmail.com.&lt;br /&gt;
In this example we will create an Access Control list (ACL) to prevent SSL interception to *.hotmail.com and *.dropbox.com.  Remember that rule order is important, the first match wins!  So put more specific rules at the top, more general rules below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Disable ssl interception for dropbox.com and hotmail.com (and localhost)&lt;br /&gt;
acl no_ssl_interception dstdomain .dropbox.com .hotmail.com&lt;br /&gt;
ssl_bump none localhost&lt;br /&gt;
ssl_bump none no_ssl_interception&lt;br /&gt;
## Add the rest of your ssl-bump rules below&lt;br /&gt;
## e.g ssl_bump server-first all&lt;br /&gt;
## etc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Further reading ====&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/HTTPS Squid HTTPS feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/SslBump Squid SSL bump feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/BumpSslServerFirst Squid bump-server-first feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/MimicSslServerCert Squid SSL cert mimic feature]&lt;br /&gt;
&lt;br /&gt;
[http://wiki.squid-cache.org/Features/DynamicSslCert Squid dynamic certificate generation page]&lt;br /&gt;
&lt;br /&gt;
== Advert blocking ==&lt;br /&gt;
There are several methods to achieve this, you could simply create an ACL for known advert domains (see [[#Blocking_domains|blocking domains]] for an indication of how to do this).&lt;br /&gt;
Another options is to use a [https://en.wikipedia.org/wiki/Hosts_%28file%29 hosts file] specific to squid (i.e. unrelated to the system hosts file), which will direct traffic for known adverts/malware sites to the localhost. The connection can then either fail (because there is no web server running at 127.0.0.1:80 to service the requests that are redirected by the hosts file to localhost) and squid will display a standard error, or you can have a web server running that will respond with some form of &#039;advert blocked&#039; page.&lt;br /&gt;
&lt;br /&gt;
Blocking ads will save bandwidth and should improve page load times.  As a drawback, some pages may look untidy or odd without advertising in place.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is either create a hosts file yourself or find a pre-configured one such as [http://winhelp2002.mvps.org/hosts.txt this one] (note that this file is free to use for personal use only, see the full license [http://creativecommons.org/licenses/by-nc-sa/3.0/ here].&lt;br /&gt;
&lt;br /&gt;
Whichever method you choose, save the hosts file to the local filesystem, in our example to &amp;lt;code&amp;gt;/etc/squid/hosts.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, add the &amp;lt;code&amp;gt;hosts_file&amp;lt;/code&amp;gt; directive to the squid configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hosts_file /etc/squid/hosts.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember to reload the configuration/restart the squid service for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
== Blocking domains ==&lt;br /&gt;
&lt;br /&gt;
If you have a large number of domains you wish to block, instead of adding them directly to the squid configuration file the best option is to create a separate list and reference this in the configuration file.&lt;br /&gt;
The domain list should have domains listed one per line.  There is an example list (warning, this doesn&#039;t get updated!) available [https://dl.dropboxusercontent.com/u/30359454/Squid/porndomains.acl here] or [http://www.ginjachris.co.uk/porndomains.acl here] &lt;br /&gt;
We will refer to this list in our example below.&lt;br /&gt;
&lt;br /&gt;
- Create your own, or download a domain list and save it to {{Path|/etc/squid/porndomains.acl}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
wget http://www.ginjachris.co.uk/porndomains.acl -O /etc/squid/porndomains.acl&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Amend the squid configuration file at {{Path|/etc/squid/squid.conf}} as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 # block porn domains based on a URL filtering list&lt;br /&gt;
 acl blacklistpr0n dstdomain &amp;quot;/etc/squid/porndomains.acl&amp;quot;&lt;br /&gt;
 http_access deny blacklistpr0n&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Check the squid configuration for errors: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k check&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and if there are none, apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
squid -k reconfigure&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
- Done!  Domains from the list should now be blocked.&lt;br /&gt;
&lt;br /&gt;
You can of course create your own lists of domains and add blacklists/whitelists to your configuration based on the above example.  Each list should of course have a unique name.&lt;br /&gt;
&lt;br /&gt;
== DNS configuration ==&lt;br /&gt;
No additional DNS configuration is required since by default Squid will use the settings in /etc/resolv.conf.&lt;br /&gt;
You may wish to change this behaviour for your environment or tweak settings to improve performance, as per the below example.  It&#039;s heavily commented as always for my examples, change to suit your needs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Use DNS defined servers.  Default is to use servers defined in /etc/resolv.conf &lt;br /&gt;
#dns_nameservers 10.0.0.1 192.168.0.1&lt;br /&gt;
## Should squid handle single-component names?  Default is disabled&lt;br /&gt;
#dns_defnames enabled&lt;br /&gt;
## How many DNS child processes to spawn?  Values shown are defaults&lt;br /&gt;
#dns_children 32 startup=1 idle=1&lt;br /&gt;
## Enable EDNS.  Default is no (&amp;quot;none&amp;quot;).  Size is specified in bytes.&lt;br /&gt;
#dns_packet_max none&lt;br /&gt;
## How often to retransmit DNS query?  Default is 5 seconds, doubled every time all DNS servers have been tried.&lt;br /&gt;
#dns_retransmit_interval 5&lt;br /&gt;
## DNS query timeout. If no response is received to a DNS query within this time,&lt;br /&gt;
## all DNS servers for the queried domain are assumed to be unavailable.&lt;br /&gt;
## Default is 30 seconds&lt;br /&gt;
#dns_timeout 30 seconds&lt;br /&gt;
## Default is to use IPv6 to connect to sites where available, over IPv4.&lt;br /&gt;
## Turning this feature on reverses this and prefers IPv4 connections over IPv6&lt;br /&gt;
#dns_v4_first on &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
[http://www.squid-cache.org/Doc/config/ Squid configuration directives]&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/8/squid Squid man page]&lt;br /&gt;
&lt;br /&gt;
[https://wiki.archlinux.org/index.php/Squid Squid Arch linux wiki page]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=9994</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=9994"/>
		<updated>2014-05-29T13:41:52Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some awesome acoustic punk tunes I&#039;ve discovered recently:&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/My+Idea+Of+Fun/2LX80k?src=5 &#039;My idea of fun&#039; by Wingnut Dishwashers Union]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Gimme+Coffee+Or+Death/3VTYAr?src=5 &#039;Gimme coffee or death&#039; by Mischief Brew]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Picking+Sides/2LX6ZZ?src=5 &#039;Picking sides&#039; by Wingnut Dishwashers Union]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/DIY+Orgasms/17PM7B?src=5 &#039;DIY orgasms&#039; by Jonny Hobo and the Freight Trains]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/For+An+Old+Kentucky+Anarchist/46iV2L?src=5 &#039;For an old Kentucky Anarchist&#039; by The Orphans]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Tone+Deaf/4Pmbc0?src=5 &#039;Tone Deaf&#039; by No Cops for Miles]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
Courtesy of BitL0G1c:&lt;br /&gt;
# Automatically do an ls after each cd&lt;br /&gt;
 c() {&lt;br /&gt;
   if [ -n &amp;quot;$1&amp;quot; ]; then&lt;br /&gt;
     cd &amp;quot;$@&amp;quot; &amp;amp;&amp;amp; ls&lt;br /&gt;
   else&lt;br /&gt;
     cd ~ &amp;amp;&amp;amp; ls&lt;br /&gt;
   fi&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=9993</id>
		<title>User:Ginjachris</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Ginjachris&amp;diff=9993"/>
		<updated>2014-05-29T13:37:07Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, my name is Chris and I&#039;m a security analyst from the UK.  I&#039;m no coder so I&#039;m currently contributing to the wiki and suggesting improvements.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some awesome acoustic punk tunes I&#039;ve discovered recently:&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/My+Idea+Of+Fun/2LX80k?src=5 &#039;My idea of fun&#039; by Wingnut Dishwashers Union]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Gimme+Coffee+Or+Death/3VTYAr?src=5 &#039;Gimme coffee or death&#039; by Mischief Brew]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Picking+Sides/2LX6ZZ?src=5 &#039;Picking sides&#039; by Wingnut Dishwashers Union]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/DIY+Orgasms/17PM7B?src=5 &#039;DIY orgasms&#039; by Jonny Hobo and the Freight Trains]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/For+An+Old+Kentucky+Anarchist/46iV2L?src=5 &#039;For an old Kentucky Anarchist&#039; by The Orphans]&lt;br /&gt;
&lt;br /&gt;
[http://grooveshark.com/s/Tone+Deaf/4Pmbc0?src=5 &#039;Tone Deaf&#039; by No Cops for Miles]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pages I need to write:&lt;br /&gt;
&lt;br /&gt;
* Time: the importance of time, plus Chrony &amp;amp; NTPD, how to run them as a client only and how to run them as a time server&lt;br /&gt;
* Ash: modifying prompt etc, using ~/.profile&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Need a wiki article?  Add it to the discussion page and I&#039;ll see what I can do :¬)&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=9969</id>
		<title>Lighttpd Advanced security</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Lighttpd_Advanced_security&amp;diff=9969"/>
		<updated>2014-05-11T20:46:38Z</updated>

		<summary type="html">&lt;p&gt;Ginjachris: /* Perfect Forward Secrecy (PFS) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For higher security [[Lighttpd]] can be configured to allow https access. &lt;br /&gt;
&lt;br /&gt;
==Generate Certificate and Keys==&lt;br /&gt;
Either generate the public key and certificate and private key using {{Pkg|openssl}}, or by using the ones generated by installing [[Alpine_Configuration_Framework_Design| ACF]].  You don&#039;t need to do both, just do one or the other.  The former method, with OpenSSL, is preferred since it gives greater control.&lt;br /&gt;
&lt;br /&gt;
===Generate self-signed certificates with openssl ===&lt;br /&gt;
To generate certificates, openssl is needed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add openssl}}&lt;br /&gt;
&lt;br /&gt;
Change to the lighttpd configuration directory&lt;br /&gt;
&lt;br /&gt;
{{Cmd|cd /etc/lighttpd}}&lt;br /&gt;
&lt;br /&gt;
With the command below the self-signed certificate and key pair are generated. A 2048 bit key is the minimum recommended at the time of writing, so we use &#039;-newkey rsa:2048&#039; in the command.  Change to suit your needs. Answer all questions.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|openssl req -newkey rsa:2048 -x509 -keyout server.pem -out server.pem -days 365 -nodes}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
=== Generate self-signed certificates with acf ===&lt;br /&gt;
&lt;br /&gt;
Install the [[Alpine_Configuration_Framework_Design| ACF]]&lt;br /&gt;
&lt;br /&gt;
{{Cmd|setup-acf}}&lt;br /&gt;
&lt;br /&gt;
Copy the generated certificate to the lighttpd configuration directory.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|mv /etc/ssl/mini_httpd/server.pem /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
Adjust the permissions&lt;br /&gt;
&lt;br /&gt;
{{Cmd|chown root:root /etc/lighttpd/server.pem}}&lt;br /&gt;
{{Cmd|chmod 400 /etc/lighttpd/server.pem}}&lt;br /&gt;
&lt;br /&gt;
mini_http is no longer needed. &lt;br /&gt;
&lt;br /&gt;
{{Cmd|/etc/init.d/mini_httpd stop &amp;amp;&amp;amp; rc-update del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
Removing the mini_http package&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk del mini_httpd}}&lt;br /&gt;
&lt;br /&gt;
==Configure Lighttpd==&lt;br /&gt;
The configuration of lighttpd needs to be modified.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|nano /etc/lighttpd/lighttpd.conf}}&lt;br /&gt;
&lt;br /&gt;
Uncomment this section and adjust the path so &#039;ssl.pemfile&#039; points to where our cert/key pair is stored. Or copy the example below into your configuration file if you saved it to /etc/lighttpd/server.pem.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.engine    = &amp;quot;enable&amp;quot;&lt;br /&gt;
ssl.pemfile   = &amp;quot;/etc/lighttpd/server.pem&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You&#039;ll also want to set the server to listen on port 443. Replace this:&lt;br /&gt;
 server.port		= 80&lt;br /&gt;
with this:&lt;br /&gt;
 server.port		= 443&lt;br /&gt;
&lt;br /&gt;
Restart lighttpd &lt;br /&gt;
&lt;br /&gt;
{{Cmd|rc-service lighttpd restart}}&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
&lt;br /&gt;
=== BEAST attack, CVE-2011-3389 ===&lt;br /&gt;
To help mitigate the BEAST attack add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
 #### Mitigate BEAST attack:&lt;br /&gt;
 &lt;br /&gt;
 # A stricter base cipher suite. For details see:&lt;br /&gt;
 # http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2011-3389&lt;br /&gt;
 # or&lt;br /&gt;
 # http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3389&lt;br /&gt;
 &lt;br /&gt;
 ssl.cipher-list = &amp;quot;ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
 # Make the server prefer the order of the server side cipher suite instead of the client suite.&lt;br /&gt;
 # This is necessary to mitigate the BEAST attack (unless you disable all non RC4 algorithms).&lt;br /&gt;
 # This option is enabled by default, but only used if ssl.cipher-list is set.&lt;br /&gt;
 ssl.honor-cipher-order = &amp;quot;enable&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Mitigate CVE-2009-3555 by disabling client triggered renegotiation&lt;br /&gt;
 # This option is enabled by default.&lt;br /&gt;
 #&lt;br /&gt;
 ssl.disable-client-renegotiation = &amp;quot;enable&amp;quot;&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Perfect Forward Secrecy (PFS) ===&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Perfect_forward_secrecy Perfect Forward Secrecy] isn&#039;t perfect, but what it does mean is that an adversary who gains the private key of a server does not have the ability to decrypt every encrypted SSL/TLS session.  Without it, an adversary can simply obtain the private key of a server and decrypt and and all SSL/TLS sessions using that key.  This is a major security and privacy concern and so using PFS is probabky a good idea long term. It means that every session would have to be decrypted individually, regardless of the state (whether obtained by the adversary or otherwise).&lt;br /&gt;
&lt;br /&gt;
Utlimately when choosing SSl/TLS ciphers it is the usual chose of security or usablilty?  Increasing one usually decreases the other.  Nonetheles, an example to prevent the BEAST attack and offer PFS is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssl.cipher-list = &amp;quot;ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://raymii.org/s/tutorials/Pass_the_SSL_Labs_Test_on_Lighttpd_%28Mitigate_the_CRIME_and_BEAST_attack_-_Disable_SSLv2_-_Enable_PFS%29.html Source]&lt;br /&gt;
&lt;br /&gt;
{{Note|Interestingly the [https://en.wikipedia.org/wiki/Satan Hebrew for Satan] is adversary; does this mean the NSA is Satan?}}&lt;br /&gt;
&lt;br /&gt;
== Other configurations ==&lt;br /&gt;
The following are example configs, they will likely need to be modified to suite your particular setup.  Nonetheless they should provide an indication of how to implement the relevant configuration options.&lt;br /&gt;
&lt;br /&gt;
=== redirecting HTTP to HTTPS ===&lt;br /&gt;
Any requests to the server via HTTP (TCP port 80 by default) will be redirected to HTTPS (port 443):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Ensure mod_redirect is enabled!&lt;br /&gt;
server.modules              = (&lt;br /&gt;
                                &amp;quot;mod_redirect&amp;quot;,                                    &lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:80&amp;quot; {&lt;br /&gt;
  $HTTP[&amp;quot;host&amp;quot;] =~ &amp;quot;(.*)&amp;quot; {&lt;br /&gt;
    url.redirect = ( &amp;quot;^/(.*)&amp;quot; =&amp;gt; &amp;quot;https://%1/$1&amp;quot; )&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
## Make sure the line above points to your SSL cert/key pair!&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serving both HTTP and HTTPS requests ===&lt;br /&gt;
Simple, just add in the SSL server port, enable the SSL engine and point to the relevant SSL cert/key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
server.port		= 80&lt;br /&gt;
server.username		= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.groupname	= &amp;quot;lighttpd&amp;quot;&lt;br /&gt;
server.document-root	= &amp;quot;/var/www/localhost/htdocs&amp;quot;&lt;br /&gt;
server.errorlog		= &amp;quot;/var/log/lighttpd/error.log&amp;quot;&lt;br /&gt;
dir-listing.activate	= &amp;quot;enable&amp;quot;&lt;br /&gt;
index-file.names	= ( &amp;quot;index.html&amp;quot; )&lt;br /&gt;
mimetype.assign		= ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot;, &amp;quot;.txt&amp;quot; =&amp;gt; &amp;quot;text/plain&amp;quot;, &amp;quot;.jpg&amp;quot; =&amp;gt; &amp;quot;image/jpeg&amp;quot;, &amp;quot;.png&amp;quot; =&amp;gt; &amp;quot;image/png&amp;quot;, &amp;quot;&amp;quot; =&amp;gt; &amp;quot;application/octet-stream&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
## Below is HTTPS setup. Make sure to point at relevant cert/key pair for HTTPS to work!&lt;br /&gt;
$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;:443&amp;quot; {&lt;br /&gt;
    ssl.engine                  = &amp;quot;enable&amp;quot; &lt;br /&gt;
    ssl.pemfile                 = &amp;quot;/etc/lighttpd/certs/www.example.com.pem&amp;quot; &lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== More details ==&lt;br /&gt;
* [http://redmine.lighttpd.net/wiki/1/Docs:SSL Lighttpd documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Ginjachris</name></author>
	</entry>
</feed>