Set Up Proxy on Amazon EC2 Ubuntu
Updated: 2023-11-28
2 min read
On This Page
1. Setting up the EC2 Instance
Launch an EC2 Instance
- Choose an Ubuntu Server image.
- Select an appropriate instance type.
- Configure instance details, storage, and security group. Ensure your security group allows inbound traffic on the ports you plan to use for your proxy (typically port 3128 for Squid).
- Review and launch the instance.
- Create and download a key pair for SSH access. (optional, can connect through AWS console later)
2. Connect to Your Instance
Use SSH client with the instance’s public DNS/IP and the key pair:
ssh -i /path/to/your-key.pem ubuntu@your-instance-public-dns
Or through AWS Session Manager
Installing and Configuring Squid
Install Squid
- Update package lists: sudo apt-get update
- Install Squid: sudo apt-get install squid apache2-utils
Configure Squid with Authentication
- Open the Squid configuration file: sudo nano /etc/squid/squid.conf
- Configure basic settings:
Set http_port to your desired port, typically 3128.
Add the following lines for basic authentication:
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic realm proxy acl authenticated proxy_auth REQUIRED http_access allow authenticated
Create a username and password
Use
htpasswd
to create an encrypted password file and userapt install apache2-utils sudo htpasswd -c /etc/squid/passwd your_username
You’ll be prompted to enter and confirm a password for your_username.
Save and close the file.
- Restart Squid:
- Apply configuration changes:
sudo systemctl restart squid
- Apply configuration changes:
Testing the Proxy
- From a client machine, try accessing the internet or a specific website while the proxy settings are enabled.
- You should be able to browse the internet through your EC2 proxy.