Cool Solution - Squid as Reverse SSL Proxy

This article describes how to configure Squid3 as a reverse proxy with HTTPS and SSL support. This allows to proxy your secured application without exposing your Webserver to the outside or to loadbalance between multiple SSL Servers.

Requirements

To install Squid3 for UCS 4, execute the following command:

univention-app install squid

In addition you need the private key and the public certificate from the squid server (/etc/univention/ssl/…). In the following, we refer to the certificate as cert.pem, to the key as private.key and to the server you want to tunnel to as DSTHOST.

Note: Everything within a less-than sign (<) and a greater-than sign (>) must be replaced with your own values. Less-than sign (<) and greater-than sign (>) must be replaced as well.

Note: myHost and myNetwork are variable values and may be changed to own use.

Pre-Configuration

At first, the Apache Server must be stopped and disabled within its UCR variable. This is necessary to free the HTTPS port for Squid3

service apache2 stop
ucr set apache2/autostart="no"

Configure Squid

Afterwards, the local configuration file /etc/squid/local_bottom.conf must be edited.
If there is already a configuration in this file, you should make a backup of that:

cp /etc/squid/local_bottom.conf /etc/squid/local_bottom.conf.backup

To configure your reverse SSL proxy, add the following lines to your configuration.

#reverse SSL proxy
https_port 443 cert=</path/to/cert.pem> key=</path/to/private.key> accel defaultsite=<FQDN of DSTHOST> vhost
cache_peer <IP of DSTHOST> parent 443 0 no-query proxy-only originserver ssl sslflags=DONT_VERIFY_PEER name=myHost

The given name is needed below again, if custom ACLs are to be created (optional)

Configure ACLs

After the reverse proxy is configured, the next step is to configure ACLs to define who is able to access your site and who is not. At first, we define an ACL for a network. This is possible with UCR or via manually editing the config file. The latter is only needed when the network MUST have a certain name.

To grant access to a whole network, you can use the UCR variable squid/allowfrom. Multiple networks can be separated with spaces.

ucr set squid/allowfrom='<NETWORK>/<CIDR NETWORK MASK>'

So, if we’d want to allow IPs from the network 192.168.0.0/24, the command would look as follows:

ucr set squid/allowfrom='192.168.0.0/24'

The network will be named dynamically, starting with localnet1.

Note: The rules for cache_peer_access and the rules for your reverse SSL proxy (https_port, cache_peer) have to be made directly in the local config.

Alternatively, for example if you need to give the network a certain name, you can apply this configuration manually in your local_bottom.conf with these lines (this is completely optional):

  
 acl myNetwork src <NETWORK>/<CIDR NETWORK MASK>
 
 #########
 # rules #
 #########

Additionally, the rules for our newly created ACL would have to be defined

 http_access allow myNetwork
 cache_peer_access myHost allow myNetwork
 
 # deny the rest
 http_access deny all
 http_reply_access allow all
 icp_access allow all

Since Squid3 is a mighty product, we can’t cover all cases you may want to define here. Please refer to the official documentation linked in the Further Information section.

After your changes have been saved, squid3 needs to be restarted:

service squid restart

Afterwards your reverse proxy should be working.

Further Information

http://www.squid-cache.org/Doc/config/

Mastodon