Skip to content

Instantly share code, notes, and snippets.

@pablomdo
Created April 7, 2023 19:58
Show Gist options
  • Save pablomdo/3a9285a62744dde2b8e11973e02e0f3a to your computer and use it in GitHub Desktop.
Save pablomdo/3a9285a62744dde2b8e11973e02e0f3a to your computer and use it in GitHub Desktop.
Docker Squid proxy server example
Create a folder named "proxy-server" and copy the files there.
Run "bash build.sh"
Then "bash run.sh"
You will have a Squid proxy server running on port 3128 (you can change the port to whatever you want)
Configure HTTP Proxy settings on IntelliJ.
Host name: localhost
Port number: 3128
Check the instructions here if you need: https://www.jetbrains.com/help/idea/settings-http-proxy.html
#!/bin/bash
docker build -t proxy-server .
# Use the official Ubuntu 20.04 image as the base
FROM ubuntu:20.04
# Set environment variables to avoid interactive installation
ENV DEBIAN_FRONTEND=noninteractive
# Update package list and install Squid
RUN apt-get update && \
apt-get install -y squid
# Copy custom Squid configuration file
COPY squid.conf /etc/squid/squid.conf
# Expose the Squid port
EXPOSE 3128
# Run Squid in the foreground
CMD ["squid", "-N"]
#!/bin/bash
CONTAINER_NAME="proxy-server-container"
IMAGE_NAME="proxy-server"
PORT=3128
# Check if the container is running
if docker ps --format "{{.Names}}" | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Stopping running container..."
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
elif docker ps -a --format "{{.Names}}" | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Removing stopped container..."
docker rm $CONTAINER_NAME
fi
# Start the container
echo "Starting the container..."
docker run -d --name proxy-server-container -p $PORT:$PORT proxy-server
echo "Done."
http_port 3128
http_access allow all
cache deny all
forwarded_for delete
via off
# Enable SSL bump
ssl_bump allow all
# Don't verify server certificates
sslproxy_cert_error allow all
sslproxy_flags DONT_VERIFY_PEER
@vaishnavn02
Copy link

vaishnavn02 commented Apr 19, 2023

For setting up this proxy server on windows, could you suggest where i could download the squid installer.

Regards

Vaishnav

@pablomdo
Copy link
Author

pablomdo commented Apr 21, 2023

For setting up this proxy server on windows, could you suggest where i could download the squid installer.

Regards

Vaishnav

You can use the same Dockerfile on Windows, just make sure you have Docker installed.
The only thing that changes is the fact you wont be able to execute the run.sh script. But you can run the container with the following commands:

Build the docker image:
docker build -t proxy-server .

Run a container based on the built image:
docker run -d --name proxy-server-container -p 3128:3128 proxy-server

Then you'll have a squid server running on port 3128

@crftr
Copy link

crftr commented May 29, 2023

Thanks for sharing, @kryptogeist!

The sslproxy_flags directive appears to be obsolete since Squid v3.3. It appears that it should be replaced with tls_outgoing_options flags=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment