Building a Simple Proxy Server with Raspberry Pi

Discover the simplicity of setting up a proxy server on your Raspberry Pi using the user-friendly and open-source software known as Squid. In this tutorial, we provide a step-by-step guide, demonstrating its application for web scraping. However, the advantages of establishing a proxy server extend beyond this, encompassing enhanced security, efficient caching, accelerated networking requests, and streamlined connection management. Unlock the potential of your Raspberry Pi with this comprehensive tutorial on Squid proxy server setup!
Before reading the remainder, be sure to subscribe and support the channel if you have not!
Subscribe:
Support:
Hire me at UpWork to build your IoT projects:

Part 1: Setting up the Raspberry Pi

Initial Setup:
- Ensure your Raspberry Pi 4 is set up with Raspbian (or another compatible OS) and that it's connected to the internet.
- Access your Raspberry Pi terminal through SSH or directly using a monitor and keyboard.
Update and Upgrade Packages:
- Run sudo apt-get update and sudo apt-get upgrade to ensure all packages are up to date.
Install Squid:
- Execute sudo apt-get install squid.
- Once installed, the Squid service should start automatically.
Configure Squid:
- Backup the original configuration file: sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.backup.
- Edit the configuration file: sudo nano /etc/squid/squid.conf.
You can see the lines are uncommented:
acl localnet src 192.168.1.0/24
http_access allow localnet
This is needed to only allow devices on your local home network to connect to the proxy. It is a very simple setting; you can play with the config in this file to filter what IPs and what network security parameters you would like to configure. For the sake of this video, we keep it simple.
Restart Squid:
- Restart the Squid service to apply the changes: sudo systemctl restart squid.
Verify Squid is Running:
- Check the status of Squid: sudo systemctl status squid.
Get Raspberry Pi IP Address:
To get the Raspberry Pi IP address you can type in the command ifconfig in the terminal and look at the inet address. You will need this address to use on the Python script on your local computer that will send the scraping request to the Pi's IP address first as proxy!

Part 2: Local Computer Code

Create a Python Script on your local computer and run the following script, make sure you substitute your Pi IP address.
This script is designed to scrape web content from a specified URL (in this case, a search page on eBay for laptops) using the Python requests library for making HTTP requests and the BeautifulSoup library from bs4 for parsing HTML content. The script uses a proxy server to make the request. 
    In a real-world scenario, you'd likely want to add more functionality after parsing the HTML to extract and process the specific data you're interested in.

    Conclusion:

    Hope you enjoyed the quick tutorial, if the Python script ran it means that the requests are going through your Pi's IP address which can help you webscrape, let me know if you have any questions.
    If you enjoy the video, please subscribe to my channel Shilleh on Youtube in the video above, your support would be appreciated. Ping me for any questions, thanks everyone!

    Create a free account to access full content.

    All access to code and resources on ShillehTek.

    Signup Now

    Already a member? Sign In

    Explore More on Our Blog

    Controlling a 5V Laser Diode with Raspberry Pi Pico W

    Controlling a 5V Laser Diode with Raspberry Pi Pico W

    Learn how to safely control high-power components like a 5V laser diode using the Raspberry Pi Pico W and a...

    How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

    How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

    Learn how to set up the HCSR501 PIR sensor with a Raspberry Pi Pico to detect motion and trigger...

    Powering the Raspberry Pi Pico W with the MB102 Power Supply

    Powering the Raspberry Pi Pico W with the MB102 Power Supply

    Learn how to power your Raspberry Pi Pico W projects easily and flexibly with the MB102 Power Supply Module...

    How to Use L298N Motor Driver with Pico W

    How to Use L298N Motor Driver with Pico W

    Learn how to use the L298N motor driver to control DC motors with the Raspberry Pi Pico W in MicroPython.

    Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

    Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

    Discover how to set up, code, and activate the LED based on detected sound with the Raspberry Pi...

    Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

    Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

    In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using...

    How to Post to Reddit Using Python

    How to Post to Reddit Using Python

    Post to reddit automatically using a Python script.

    How to Create a Time-Lapse Video with a Raspberry Pi Camera

    How to Create a Time-Lapse Video with a Raspberry Pi Camera

    Learn how to make a timelapse with your Raspberry Pi in Python.

    How to Integrate the MPU6050 with the STM32 Blue Pill

    How to Integrate the MPU6050 with the STM32 Blue Pill

    Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

    Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

    Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

    This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

    Back to blog

    Leave a comment

    Please note, comments need to be approved before they are published.