Last active
April 6, 2024 06:37
-
-
Save agalea91/bf5e96b03d60a9c0237849bb682b2b0b to your computer and use it in GitHub Desktop.
Squid proxy setup on linux server (NO WARRANTY)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://linuxize.com/post/how-to-install-and-configure-squid-proxy-on-ubuntu-20-04/ | |
# Install squid | |
sudo apt update | |
sudo apt install squid | |
# Backup config | |
sudo cp /etc/squid/squid.conf{,.orginal} | |
# Add allowed IPs | |
touch /etc/squid/allowed_ips.txt | |
# Configure squid | |
vim /etc/squid/squid.conf | |
(add lines like the ones below) | |
# ... | |
acl allowed_ips src "/etc/squid/allowed_ips.txt" | |
# ... | |
#http_access allow localnet | |
http_access allow localhost | |
http_access allow allowed_ips | |
# And finally deny all other access to this proxy | |
http_access deny all | |
# Make requests from allowed hosts | |
python | |
>>> import requests | |
>>> PROXY_IP = "XXXXXXXXX" | |
>>> proxies = dict(http="http://{PROXY_IP}:3128/", https="http://{PROXY_IP}:3128/") | |
>>> resp = requests.get("https://gist.github.com/", proxies=proxies) | |
>>> resp # should be status code 200 | |
# Access with chrome | |
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --user-data-dir="$HOME/proxy-profile" --proxy-server="http://XXXXXXXXX:3128" | |
####################### | |
# OLD 2018 GUIDE BELOW | |
####################### | |
sudo apt-get update | |
sudo apt-get upgrade | |
sudo apt-get install squid | |
# copy default config | |
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original | |
sudo chmod a-w /etc/squid/squid.conf.original | |
# add to config (in correct sections! search "TAG: ___" e.g. "TAG: acl") | |
sudo vim /etc/squid/squid.conf | |
acl alex src 12.34.56.78 # insert ip here (at bottom of acl secion) | |
http_access allow alex # insert name here (at top of http_access section) | |
http_port 1234 # pick a port (at top of http_port section) | |
sudo service squid restart | |
service squid status # to check for errors | |
# Test with python requests from client computer | |
import requests | |
proxies = { | |
'http': 'http://12.34.56.78:1234/', | |
'https': 'http://12.34.56.78:1234/', | |
} | |
page = requests.get('http://docs.python-requests.org/en/master/user/advanced/', proxies=proxies) | |
# Set up basic auth (not really needed since we only allow specific IPs) | |
# see here: https://stackoverflow.com/questions/3297196/how-to-set-up-a-squid-proxy-with-basic-username-and-password-authentication |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment